CMakeLists.txt 47.1 KB
Newer Older
1 2
###
#
3 4
# @file CMakeLists.txt
#
Mathieu Faverge's avatar
Mathieu Faverge committed
5 6
# @copyright 2009-2014 The University of Tennessee and The University of
#                      Tennessee Research Foundation. All rights reserved.
7
# @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
#                      Univ. Bordeaux. All rights reserved.
9 10 11
#
###
#
12 13
#  @project CHAMELEON
#  CHAMELEON is a software package provided by:
14 15 16 17 18 19
#     Inria Bordeaux - Sud-Ouest,
#     Univ. of Tennessee,
#     King Abdullah Univesity of Science and Technology
#     Univ. of California Berkeley,
#     Univ. of Colorado Denver.
#
Mathieu Faverge's avatar
Mathieu Faverge committed
20
# @version 1.0.0
21 22 23 24
#  @author Cedric Castagnede
#  @author Emmanuel Agullo
#  @author Mathieu Faverge
#  @author Florent Pruvost
25
#  @date 2012-07-13
26 27
#
###
28
cmake_minimum_required(VERSION 3.3)
29
project(CHAMELEON Fortran C CXX)
30 31 32 33 34 35 36 37 38

# directly make an error if in-source build
if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
   message(FATAL_ERROR "In-source builds are not allowed.\n"
   "Please create a build directory first and execute cmake configuration from "
   "this directory. Example: mkdir build && cd build && cmake ..")
endif()

# set project version number
39 40 41
set(CHAMELEON_VERSION_MAJOR 1)
set(CHAMELEON_VERSION_MINOR 0)
set(CHAMELEON_VERSION_MICRO 0)
42

43
set(CHAMELEON_CMAKE_DIR "" CACHE PATH "Directory of CHAMELEON CMake modules, can be external to the project")
44 45 46

# Add extra cmake module path and initialize morse cmake modules
# --------------------------------------------------------------
47
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
48 49 50
if(CHAMELEON_CMAKE_DIR)
    list(APPEND CMAKE_MODULE_PATH "${CHAMELEON_CMAKE_DIR}/cmake_modules/morse_cmake/modules")
    set(CHAMELEON_CMAKE_MODULE_PATH ${CHAMELEON_CMAKE_DIR}/cmake_modules/morse_cmake/modules )
51
elseif(EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake")
52
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules")
53
    set(CHAMELEON_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules )
54 55
else()
  message(FATAL_ERROR "Chameleon CMake system relies on morse_cmake modules developed here: "
56
    "https://gitlab.inria.fr/solverstack/morse_cmake. Please set CHAMELEON_CMAKE_DIR to this source "
57 58
    "directory.")
endif()
59

60 61
include(MorseInit)
include(GenPkgConfig)
62

PRUVOST Florent's avatar
PRUVOST Florent committed
63 64
# Ensure that the fortran compiler and c compiler specified are compatible
# ------------------------------------------------------------------------
65
include(FortranCInterface)
66
FortranCInterface_VERIFY()
67 68
FortranCInterface_HEADER(${CMAKE_CURRENT_BINARY_DIR}/include/chameleon/mangling.h
                         MACRO_NAMESPACE "CHAMELEON_")
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

#############################################
#                                           #
#        Compilation of CHAMELEON           #
#                                           #
#############################################


###############################################################################
# Parameters/Options #
######################

# Set the RPATH config
# --------------------

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH  FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# Misc options
# ------------
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

# Define precision supported by CHAMELEON
# -----------------------------------------
100
set( RP_CHAMELEON_DICTIONNARY ${CHAMELEON_CMAKE_MODULE_PATH}/precision_generator/subs.py )
101 102 103
set( RP_CHAMELEON_PRECISIONS  "s;d;c;z" )
include(RulesPrecisions)

104
option(CHAMELEON_USE_MIGRATE
105
  "This options enables the data migration in QR algorithms" ON)
106

107 108 109 110
# Options to select the runtime
# -----------------------------

# Create a list of possible runtime
111
set(CHAMELEON_SCHED_list PARSEC STARPU QUARK OPENMP
112
  CACHE INTERNAL "List of available runtimes" )
113

114 115 116 117
set( CHAMELEON_SCHED_PARSEC OFF CACHE INTERNAL
  "Enable PaRSEC scheduler as the default runtime
    (Conflict with other CHAMELEON_SCHED_* options)")
set(CHAMELEON_SCHED_STARPU OFF CACHE INTERNAL
118
    "Enable StarPU scheduler as the default runtime
119 120 121 122
    (Conflict with other CHAMELEON_SCHED_* options)")
set(CHAMELEON_SCHED_QUARK OFF CACHE INTERNAL
  "Enable Quark scheduler as the default runtime
    (Conflict with other CHAMELEON_SCHED_* options)")
123 124 125
set(CHAMELEON_SCHED_OPENMP OFF CACHE INTERNAL
  "Enable OpenMP scheduler as the default runtime
    (Conflict with other CHAMELEON_SCHED_* options)")
126 127 128 129 130 131 132

set( CHAMELEON_SCHED STARPU
  CACHE STRING "Choose the chameleon internal runtime from ${CHAMELEON_SCHED_list}")
set_property(CACHE CHAMELEON_SCHED PROPERTY STRINGS ${CHAMELEON_SCHED_list})

if ( NOT ${CHAMELEON_SCHED} IN_LIST CHAMELEON_SCHED_list )
  message(FATAL_ERROR "CHAMELEON_SCHED must be one of ${CHAMELEON_SCHED_list} (${CHAMELEON_SCHED} is incorrect)" )
133
endif()
134 135 136

set( CHAMELEON_SCHED_${CHAMELEON_SCHED} ON )

137
# Set default to StarPU if nothing specific is required by the user
138
message("-- ${BoldGreen}CHAMELEON_SCHED is set to use ${CHAMELEON_SCHED} runtime" )
139

140 141 142 143 144 145
# Check that one, and only one, SCHED option is set to ON
# count number of runtime sets to ON
math(EXPR number_of_active_runtime 0)
foreach (runtime ${CHAMELEON_SCHED_list})
    if (CHAMELEON_SCHED_${runtime})
        math(EXPR number_of_active_runtime "${number_of_active_runtime}+1")
146
    endif()
147 148 149 150 151 152
endforeach()
if (NOT number_of_active_runtime STREQUAL 1)
    message(FATAL_ERROR
            "Number of active runtime is ${number_of_active_runtime}, "
            "the user should activate one (and only one) runtime. ")
endif()
153

154 155 156 157 158
# Use intermediate variable since cmake_dependent_option doesn't have OR conditions
set(CHAMELEON_ENABLE_MPI OFF CACHE INTERNAL "Tells if MPI might be supported by the runtime")
if ( CHAMELEON_SCHED_PARSEC OR CHAMELEON_SCHED_STARPU )
     set(CHAMELEON_ENABLE_MPI ON FORCE)
endif()
159

160 161 162 163 164
# Use intermediate variable since cmake_dependent_option doesn't have OR conditions
set(CHAMELEON_ENABLE_CUDA OFF CACHE INTERNAL "Tells if CUDA might be supported by the runtime")
if ( CHAMELEON_SCHED_PARSEC OR CHAMELEON_SCHED_STARPU )
     set(CHAMELEON_ENABLE_CUDA ON FORCE)
endif()
165

166 167
# Additional options
# ------------------
168

169 170 171 172 173 174 175 176
# Enable the distributed interface (allowed only when StarPU or PaRSEC is enabled)
# TODO: Default should be changed to ON/OFF when it will be ok
cmake_dependent_option(CHAMELEON_USE_MPI
                    "Enable distributed memory through MPI" OFF
                    "CHAMELEON_ENABLE_MPI" OFF)
if (CHAMELEON_ENABLE_MPI AND NOT CHAMELEON_USE_MPI)
    message("-- ${BoldGreen}CHAMELEON_USE_MPI is set to OFF, turn it ON to use MPI (unsupported by Quark)${ColourReset}")
endif()
177

178 179 180 181 182 183 184 185
# Enable Cuda kernels if StarPU (only if StarPU or PaRSEC runtime is enabled)
# TODO: Default should be changed to ON/OFF when it will be ok
cmake_dependent_option(CHAMELEON_USE_CUDA
                    "Enable CUDA kernels" OFF
                    "CHAMELEON_ENABLE_CUDA" OFF)
if (CHAMELEON_ENABLE_CUDA AND NOT CHAMELEON_USE_CUDA)
    message("-- ${BoldGreen}CHAMELEON_USE_CUDA is set to OFF, turn it ON to use CUDA (unsupported by Quark)${ColourReset}")
endif()
186

187 188 189 190 191 192
# Enable FXT if StarPU
option(CHAMELEON_ENABLE_TRACING "Enable tracing support" OFF)
if (NOT CHAMELEON_ENABLE_TRACING)
    message("-- ${BoldGreen}CHAMELEON_ENABLE_TRACING is set to OFF, turn it ON to use FxT (with StarPU)${ColourReset}")
endif()
#option(CHAMELEON_USE_EZTRACE "Enable EZTRACE to build modules" OFF)
193

194 195
# Options to enable/disable testings and timings
# ----------------------------------------------
196 197 198
option(CHAMELEON_ENABLE_DOC      "Enable documentation build"  OFF)
if (CHAMELEON_ENABLE_DOC)
    message("-- ${BoldGreen}CHAMELEON_ENABLE_DOC is set to ON, turn it OFF to avoid building docs${ColourReset}")
199 200 201 202 203 204 205 206 207 208 209 210 211
endif()
option(CHAMELEON_ENABLE_EXAMPLE  "Enable examples build"       ON)
if (CHAMELEON_ENABLE_EXAMPLE)
    message("-- ${BoldGreen}CHAMELEON_ENABLE_EXAMPLE is set to ON, turn it OFF to avoid building examples${ColourReset}")
endif()
option(CHAMELEON_ENABLE_TESTING  "Enable testings build"       ON)
if (CHAMELEON_ENABLE_TESTING)
    message("-- ${BoldGreen}CHAMELEON_ENABLE_TESTING is set to ON, turn it OFF to avoid building testing${ColourReset}")
endif()
option(CHAMELEON_ENABLE_TIMING   "Enable timings build"        ON)
if (CHAMELEON_ENABLE_TIMING)
    message("-- ${BoldGreen}CHAMELEON_ENABLE_TIMING is set to ON, turn it OFF to avoid building timing${ColourReset}")
endif()
212

213 214 215 216 217 218 219
# Option to activate or not simulation mode (use Simgrid through StarPU)
# ----------------------------------------------------------------------
if(CHAMELEON_SCHED_STARPU)
    option(CHAMELEON_SIMULATION "Enable simulation mode using Simgrid through StarPU" OFF)
    if (NOT CHAMELEON_SIMULATION)
        message("-- ${BoldGreen}CHAMELEON_SIMULATION is set to OFF, turn it ON to use"
            " SIMULATION mode (only with StarPU compiled with SimGrid)${ColourReset}")
220
    endif()
221 222 223 224 225 226 227
    option(CHAMELEON_ENABLE_PRUNING_STATS "Enable pruning statistics" OFF)
    if (NOT CHAMELEON_ENABLE_PRUNING_STATS)
        message("-- ${BoldGreen}CHAMELEON_ENABLE_PRUNING_STATS is set to OFF, turn it ON to build pruning statistics${ColourReset}")
    endif()
    if(CHAMELEON_ENABLE_PRUNING_STATS)
        add_definitions(-DCHAMELEON_ENABLE_PRUNING_STATS)
    endif(CHAMELEON_ENABLE_PRUNING_STATS)
228
endif()
229

230 231 232 233 234
# Initially we need to generate files for different precisions
# TODO: use this option to avoid generate multiple precisions each time we launch cmake
#option(CHAMELEON_GEN_PREC "Generate source files precisions" ON)
#------------------------------------------------------------------------------

235 236 237 238 239
###############################################################################
# Build dependency HQR library #
################################
add_subdirectory(hqr)
include_directories(hqr/include)
240 241 242 243 244 245 246 247 248 249

###############################################################################
# Look for dependencies #
#########################
set(CHAMELEON_DEP "")

# Check for Thread library
# ------------------------
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
250 251 252
if( THREADS_FOUND AND CMAKE_THREAD_LIBS_INIT )
  libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
  list(APPEND EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
253 254 255 256 257 258
endif ()

# Add math library to the list of extra
# it normally exists on all common systems provided with a C compiler
if(UNIX OR WIN32)
    find_library(
PRUVOST Florent's avatar
PRUVOST Florent committed
259
      M_LIBRARY
260 261
      NAMES m
      )
PRUVOST Florent's avatar
PRUVOST Florent committed
262 263 264
    mark_as_advanced(M_LIBRARY)
    if (M_LIBRARY)
      list(APPEND EXTRA_LIBRARIES "${M_LIBRARY}")
265
    else()
266 267
      message(FATAL_ERROR "Could NOT find libm on your system."
        " Are you sure to a have a C compiler installed?")
268
    endif()
269
endif()
270

271 272 273 274
# Try to find librt (libposix4 - POSIX.1b Realtime Extensions library)
# on Unix systems except Apple ones because it does not exist on it
if(UNIX AND NOT APPLE)
    find_library(
PRUVOST Florent's avatar
PRUVOST Florent committed
275
        RT_LIBRARY
276 277
        NAMES rt
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
278 279 280
    mark_as_advanced(RT_LIBRARY)
    if (RT_LIBRARY)
        list(APPEND EXTRA_LIBRARIES "${RT_LIBRARY}")
281 282 283 284
    else()
        message(FATAL_ERROR "Could NOT find librt on your system")
    endif()
endif()
285

286 287 288 289 290
# If simulation we don't enter in kernel functions so that we don't need to
# link with concerned libraries
if(NOT CHAMELEON_SIMULATION)
    # CHAMELEON depends on CBLAS
    #---------------------------
291 292 293 294
    find_package(CBLAS REQUIRED)
    if(CBLAS_FOUND)
        if (CBLAS_INCLUDE_DIRS_DEP)
            include_directories(${CBLAS_INCLUDE_DIRS_DEP})
295
        endif()
296
        if(CBLAS_CFLAGS_OTHER_DEP)
297
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CBLAS_CFLAGS_OTHER_DEP}")
298
            string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
299
        endif()
300
        if(CBLAS_LDFLAGS_OTHER_DEP)
301
            set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CBLAS_LDFLAGS_OTHER_DEP}")
302
            string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
303 304 305 306 307 308
        endif()
        if(CBLAS_LIBRARY_DIRS_DEP)
            list(APPEND CMAKE_INSTALL_RPATH "${CBLAS_LIBRARY_DIRS_DEP}")
        endif()
        if (CBLAS_LIBRARIES_DEP)
            list(INSERT CHAMELEON_DEP 0 ${CBLAS_LIBRARIES_DEP})
309 310
        endif()
    else()
311
        if(CHAMELEON_VERBOSE_FIND_PACKAGE)
312 313 314 315 316 317 318
            if(CBLAS_STANDALONE OR NOT CBLAS_WORKS)
                if (NOT CBLAS_cblas.h_DIRS)
                    Print_Find_Header_Status(cblas cblas.h)
                endif ()
                if (NOT CBLAS_cblas_LIBRARY)
                    Print_Find_Library_Status(cblas libcblas)
                endif ()
319
            endif()
320
        else()
321 322
            message(WARNING "CBLAS library has not been found and CHAMELEON_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate CHAMELEON_VERBOSE_FIND_PACKAGE option (-DCHAMELEON_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
323 324 325 326 327 328
        endif()
        message(FATAL_ERROR "A CBLAS library is required but has not been found")
    endif()

    # CHAMELEON depends on LAPACKE
    #-----------------------------
329
    find_package(LAPACKE REQUIRED COMPONENTS TMG)
330
    if(LAPACKE_FOUND)
331 332
        if (LAPACKE_INCLUDE_DIRS_DEP)
            include_directories(${LAPACKE_INCLUDE_DIRS_DEP})
333
        endif()
334
        if(LAPACKE_CFLAGS_OTHER_DEP)
335
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LAPACKE_CFLAGS_OTHER_DEP}")
336
            string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
337
        endif()
338
        if(LAPACKE_LDFLAGS_OTHER_DEP)
339
            set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LAPACKE_LDFLAGS_OTHER_DEP}")
340
            string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
341 342 343 344 345 346
        endif()
        if(LAPACKE_LIBRARY_DIRS_DEP)
            list(APPEND CMAKE_INSTALL_RPATH "${LAPACKE_LIBRARY_DIRS_DEP}")
        endif()
        if (LAPACKE_LIBRARIES_DEP)
            list(INSERT CHAMELEON_DEP 0 ${LAPACKE_LIBRARIES_DEP})
347 348
        endif()
    else()
349
        if(CHAMELEON_VERBOSE_FIND_PACKAGE)
350 351 352 353 354 355 356
            if (LAPACKE_STANDALONE OR NOT LAPACKE_WORKS)
                if (NOT LAPACKE_lapacke.h_DIRS)
                    Print_Find_Header_Status(lapacke lapacke.h)
                endif ()
                if (NOT LAPACKE_lapacke_LIBRARY)
                    Print_Find_Library_Status(lapacke liblapacke)
                endif ()
357
            endif()
358
        else()
359 360
            message(WARNING "LAPACKE library has not been found and CHAMELEON_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate CHAMELEON_VERBOSE_FIND_PACKAGE option (-DCHAMELEON_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
361
        endif()
362 363
        message(FATAL_ERROR "A LAPACKE library is required but has not been found")
    endif()
364

365 366 367
    # CHAMELEON depends on CUDA/CUBLAS
    #----------------------------------
    if (CHAMELEON_USE_CUDA)
368

369 370 371 372
        find_package(CUDA REQUIRED)
        if (CUDA_FOUND)
            message("-- ${Blue}Add definition CHAMELEON_USE_CUDA"
            " - Activate CUDA in Chameleon${ColourReset}")
373
            libraries_absolute_path(CUDA_LIBRARIES "$ENV{CUDA_ROOT}/lib64")
374 375 376 377 378 379 380
            set(EXTRA_LIBRARIES_CUDA)
            if(CUDA_VERSION VERSION_LESS "3.0")
                set(CUDA_HOST_COMPILATION_CPP OFF)
            endif(CUDA_VERSION VERSION_LESS "3.0")
            set(CUDA_BUILD_EMULATION OFF)
            if (CUDA_INCLUDE_DIRS)
                include_directories(${CUDA_INCLUDE_DIRS})
381
            else()
382 383 384
                message(WARNING "CHAMELEON_USE_CUDA requires"
                "\n   CUDA_INCLUDE_DIRS to be found. Be sure you have"
                "\n   cuda headers with your distribution of CUDA.")
385
            endif()
386 387 388 389 390 391 392
            if (CUDA_LIBRARIES)
                set(saved_include "${CMAKE_REQUIRED_INCLUDES}")
                set(saved_libs "${CMAKE_REQUIRED_LIBRARIES}")
                set(CMAKE_REQUIRED_INCLUDES  "${CMAKE_REQUIRED_INCLUDES};${CUDA_INCLUDE_DIRS}")
                set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${CUDA_LIBRARIES}")
                if(CUDA_VERSION VERSION_LESS "4.0")
                    set(CUDA_HAVE_PEER_DEVICE_MEMORY_ACCESS 0)
393
                else()
394
                    check_function_exists(cuDeviceCanAccessPeer CUDA_HAVE_PEER_DEVICE_MEMORY_ACCESS)
395
                endif()
396 397 398 399 400 401 402 403
                set(CMAKE_REQUIRED_INCLUDES  "${saved_include}")
                set(CMAKE_REQUIRED_LIBRARIES "${saved_libs}")
                # Add cublas if found
                if (CUDA_CUBLAS_LIBRARIES)
                    message("-- ${Blue}Add definition CHAMELEON_USE_CUBLAS"
                    " - Use GPU kernels from cuBLAS${ColourReset}")
                    list(APPEND EXTRA_LIBRARIES_CUDA ${CUDA_CUBLAS_LIBRARIES})
                    list(APPEND EXTRA_LIBRARIES_CUDA ${CUDA_LIBRARIES}) # need CUDA libs to link.
404 405
                else()
                    message(FATAL_ERROR "CHAMELEON_USE_CUDA requires"
406 407
                    "\n   CUDA_CUBLAS_LIBRARIES to be found. Be sure you have"
                    "\n   libcublas with your distribution of CUDA.")
408
                endif()
409 410 411 412
            else()
                message(FATAL_ERROR "CHAMELEON_USE_CUDA requires"
                "\n   CUDA_LIBRARIES to be found. Be sure you have"
                "\n   libcuda with your distribution of CUDA.")
413
            endif()
414 415 416
        endif (CUDA_FOUND)

        list(APPEND EXTRA_LIBRARIES ${EXTRA_LIBRARIES_CUDA})
417 418 419 420 421 422 423 424
        foreach (_lib ${EXTRA_LIBRARIES_CUDA})
            if (EXISTS ${_lib})
                get_filename_component(libdir ${_lib} PATH)
                if (EXISTS ${libdir})
                    list(APPEND CMAKE_INSTALL_RPATH "${libdir}")
                endif()
            endif()
        endforeach()
425

426
    endif(CHAMELEON_USE_CUDA)
427

428 429 430
    # CHAMELEON depends on MPI
    #-------------------------
    if (CHAMELEON_USE_MPI)
431

432 433 434 435 436
        # allows to use an external mpi compilation by setting compilers with
        # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
        # at cmake configure
        if(NOT MPI_C_COMPILER)
            set(MPI_C_COMPILER mpicc)
437
        endif()
438 439 440 441 442 443 444 445 446 447
        find_package(MPI REQUIRED)

        if (MPI_C_FOUND)
            message("-- ${Blue}Add definition CHAMELEON_USE_MPI"
            " - Activate MPI in Chameleon${ColourReset}")
            list(APPEND EXTRA_LIBRARIES ${MPI_C_LIBRARIES} )
            include_directories( ${MPI_C_INCLUDE_PATH} )
            # tests for intel mpi
            #list(APPEND MPI_C_COMPILE_FLAGS "-mt_mpi")
            #list(APPEND MPI_COMPILE_FLAGS "-mt_mpi")
448 449
            if(MPI_C_COMPILE_FLAGS)
                set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS}")
450
                string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
451
            endif()
452
            if(MPI_C_LINK_FLAGS)
453
                set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_C_LINK_FLAGS}")
454
                string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
455
            endif()
456 457
        endif (MPI_C_FOUND)

458 459 460 461 462 463 464 465 466
        foreach (_lib ${MPI_C_LIBRARIES})
            if (EXISTS ${_lib})
                get_filename_component(libdir ${_lib} PATH)
                if (EXISTS ${libdir})
                    list(APPEND CMAKE_INSTALL_RPATH "${libdir}")
                endif()
            endif()
        endforeach()

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    endif (CHAMELEON_USE_MPI)

else (NOT CHAMELEON_SIMULATION)

    message("-- ${BoldBlue}Simulation mode of CHAMELEON is activated (CHAMELEON_SIMULATION=ON)."
    "\n   This mode allows you to simulate execution of algorithms with StarPU compiled with SimGrid."
    "\n   To do so, we provide some perfmodels in the simucore/perfmodels/ directory of CHAMELEON sources."
    "\n   The resulting directory where to find perfmodels is: ${CMAKE_CURRENT_SOURCE_DIR}/simucore/perfmodels."
    "\n   To use these perfmodels, please set your STARPU_HOME environment variable to ${CMAKE_CURRENT_SOURCE_DIR}/simucore/perfmodels."
    "\n   Finally, you need to set your STARPU_HOSTNAME environment variable to the name of the machine to simulate."
    "\n   For example: STARPU_HOSTNAME=mirage."
    "\n   Note that only POTRF kernels with block sizes of 320 or 960 (simple and double precision) on mirage machine are available for now."
    "\n   Database of models is subject to change, it should be enrich in a near future.${ColourReset}")

    message("-- ${Blue}Add definition CHAMELEON_SIMULATION"
    " - Activate simulation mode in Chameleon (to use with StarPU+SimGrid)${ColourReset}")

    add_subdirectory(simucore)

    # Guard against mis-used simulation mode
    if(NOT DEFINED CHAMELEON_USE_CUDA)
        message(FATAL_ERROR "${BoldBlue}"
489
        "In simulation mode CHAMELEON_USE_CUDA should be set to"
490 491 492
        "   ensure that the user is aware of the version to be used. If Chameleon's"
        "   kernels are available for NVIDIA CUDA GPUs and if the according"
        "   perfmodels are available in STARPU_HOME then use CHAMELEON_USE_CUDA=ON"
493
        "   else set CHAMELEON_USE_CUDA=OFF."
494 495
        "${ColourReset}")
    endif()
496

497 498 499 500
    if (NOT CHAMELEON_SCHED_STARPU)
        message(FATAL_ERROR "Simulation mode of Chameleon only works with"
        "\n   the StarPU runtime. Please use CHAMELEON_SCHED_STARPU=ON.")
    endif()
501

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
    if (CHAMELEON_ENABLE_EXAMPLE)
        set(CHAMELEON_ENABLE_EXAMPLE OFF)
        message("-- ${BoldBlue}CHAMELEON_ENABLE_EXAMPLE is set to ON but we turn it OFF.")
    endif ()
    if (CHAMELEON_ENABLE_TESTING)
        set(CHAMELEON_ENABLE_TESTING OFF)
        message("-- ${BoldBlue}CHAMELEON_ENABLE_TESTING is set to ON but we turn it OFF."
            "\n   Because we are compiling the simulation mode (CHAMELEON_SIMULATION=ON),"
            "\n   there is no sense in compiling testing drivers that are used to check"
            "\n   numerical correctness of algorithms and kernels.${ColourReset}")
    endif ()

    # Simulation mode: we depend on SimGrid
    find_package(SIMGRID REQUIRED)

    # CHAMELEON depends on MPI
    #-------------------------
    if (CHAMELEON_USE_MPI)

        # allows to use an external mpi compilation by setting compilers with
        # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
        # at cmake configure
        if(NOT MPI_C_COMPILER)
            set(MPI_C_COMPILER "${SIMGRID_DIR_FOUND}/bin/smpicc")
        endif()
        if(NOT MPI_C_LIBRARIES)
            set(MPI_C_LIBRARIES "${SIMGRID_LIBRARIES}")
        endif()
        if(NOT MPI_C_INCLUDE_PATH)
            set(MPI_C_INCLUDE_PATH "${SIMGRID_INCLUDE_DIRS}")
            list(APPEND MPI_C_INCLUDE_PATH "${SIMGRID_INCLUDE_DIRS}/smpi")
        endif()
        if(NOT MPI_CXX_COMPILER)
            set(MPI_CXX_COMPILER "${SIMGRID_DIR_FOUND}/bin/smpicxx")
        endif()
        if(NOT MPI_CXX_LIBRARIES)
            set(MPI_CXX_LIBRARIES "${SIMGRID_LIBRARIES}")
        endif()
        if(NOT MPI_CXX_INCLUDE_PATH)
            set(MPI_CXX_INCLUDE_PATH "${SIMGRID_INCLUDE_DIRS}")
            list(APPEND MPI_CXX_INCLUDE_PATH "${SIMGRID_INCLUDE_DIRS}/smpi")
        endif()
        if(NOT MPI_Fortran_COMPILER)
            set(MPI_Fortran_COMPILER "${SIMGRID_DIR_FOUND}/bin/smpicxx")
        endif()
        if(NOT MPI_Fortran_LIBRARIES)
            set(MPI_Fortran_LIBRARIES "${SIMGRID_LIBRARIES}")
        endif()
        if(NOT MPI_Fortran_INCLUDE_PATH)
            set(MPI_Fortran_INCLUDE_PATH "${SIMGRID_INCLUDE_DIRS}")
            list(APPEND MPI_Fortran_INCLUDE_PATH "${SIMGRID_INCLUDE_DIRS}/smpi")
        endif()
        find_package(MPI REQUIRED)

        if (MPI_C_FOUND)
            message("-- ${Blue}Add definition CHAMELEON_USE_MPI"
            " - Activate MPI in Chameleon${ColourReset}")
            list(APPEND EXTRA_LIBRARIES ${MPI_C_LIBRARIES} )
            include_directories( ${MPI_C_INCLUDE_PATH} )
561 562
            if(MPI_C_COMPILE_FLAGS)
                set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS}")
563
                string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
564
            endif()
565
            if(MPI_C_LINK_FLAGS)
566
                set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_C_LINK_FLAGS}")
567
                string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
568
            endif()
569
        endif (MPI_C_FOUND)
570

571
    endif (CHAMELEON_USE_MPI)
572

573 574 575 576 577 578 579 580 581
    foreach (_lib ${SIMGRID_LIBRARIES} ${MPI_C_LIBRARIES})
        if (EXISTS ${_lib})
            get_filename_component(libdir ${_lib} PATH)
            if (EXISTS ${libdir})
                list(APPEND CMAKE_INSTALL_RPATH "${libdir}")
            endif()
        endif()
    endforeach()

582
endif(NOT CHAMELEON_SIMULATION)
583 584


585 586 587
# CHAMELEON depends on a runtime
# -------------------------------
if( CHAMELEON_SCHED_STARPU )
588

589
    set(CHAMELEON_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
590

591 592 593 594 595
    # create list of components in order to make a single call to find_package(starpu...)
    if(NOT CHAMELEON_SIMULATION)
        set(STARPU_COMPONENT_LIST "HWLOC")
        if(CHAMELEON_USE_CUDA)
            list(APPEND STARPU_COMPONENT_LIST "CUDA")
596
        endif()
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
    else()
        set(STARPU_COMPONENT_LIST "SIMGRID")
    endif()
    if(CHAMELEON_USE_MPI)
        list(APPEND STARPU_COMPONENT_LIST "MPI")
    endif()
    if(CHAMELEON_ENABLE_TRACING)
        list(APPEND STARPU_COMPONENT_LIST "FXT")
    endif()

    find_package(STARPU ${CHAMELEON_STARPU_VERSION} REQUIRED
                 COMPONENTS ${STARPU_COMPONENT_LIST})

    # Add definition and include_dir if found
    if ( STARPU_FOUND )
        message("-- ${Blue}Add definition CHAMELEON_SCHED_STARPU"
        " - Activate StarPU in Chameleon${ColourReset}")
614 615 616 617 618
        if (STARPU_INCLUDE_DIRS_DEP)
            include_directories(${STARPU_INCLUDE_DIRS_DEP})
            set(CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS_DEP}")
        endif()
        if(STARPU_CFLAGS_OTHER_DEP)
619
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STARPU_CFLAGS_OTHER_DEP}")
620
            string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
621 622 623
            set(CMAKE_REQUIRED_FLAGS "${STARPU_CFLAGS_OTHER_DEP}")
        endif()
        if(STARPU_LDFLAGS_OTHER_DEP)
624
            set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STARPU_LDFLAGS_OTHER_DEP}")
625
            string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
626 627 628 629 630 631 632 633
            set(CMAKE_REQUIRED_LDFLAGS "${STARPU_LDFLAGS_OTHER_DEP}")
        endif()
        if(STARPU_LIBRARY_DIRS_DEP)
            list(APPEND CMAKE_INSTALL_RPATH "${STARPU_LIBRARY_DIRS_DEP}")
        endif()
        if (STARPU_LIBRARIES_DEP)
            list(INSERT CHAMELEON_DEP 0 ${STARPU_LIBRARIES_DEP})
            set(CMAKE_REQUIRED_LIBRARIES "${STARPU_LIBRARIES_DEP}")
634
        endif()
635
        string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
636 637
        check_function_exists(starpu_data_idle_prefetch_on_node HAVE_STARPU_IDLE_PREFETCH)
        if ( HAVE_STARPU_IDLE_PREFETCH )
638
            message("-- ${Blue}Add definition HAVE_STARPU_IDLE_PREFETCH${ColourReset}")
639
        endif()
640 641
        check_function_exists(starpu_iteration_push HAVE_STARPU_ITERATION_PUSH)
        if ( HAVE_STARPU_ITERATION_PUSH )
642
            message("-- ${Blue}Add definition HAVE_STARPU_ITERATION_PUSH${ColourReset}")
643
        endif()
644 645
        check_function_exists(starpu_data_wont_use HAVE_STARPU_DATA_WONT_USE)
        if ( HAVE_STARPU_DATA_WONT_USE )
646
            message("-- ${Blue}Add definition HAVE_STARPU_DATA_WONT_USE${ColourReset}")
647
        endif()
648 649
        check_function_exists(starpu_data_set_coordinates HAVE_STARPU_DATA_SET_COORDINATES)
        if ( HAVE_STARPU_DATA_SET_COORDINATES )
650 651
            message("-- ${Blue}Add definition HAVE_STARPU_DATA_SET_COORDINATES${ColourReset}")
        endif()
652 653
        check_function_exists(starpu_malloc_on_node_set_default_flags HAVE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS)
        if ( HAVE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS )
654
            message("-- ${Blue}Add definition HAVE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS${ColourReset}")
655
        endif()
656 657 658 659
        check_function_exists(starpu_data_set_ooc_flag HAVE_STARPU_DATA_SET_OOC_FLAGS)
        if ( HAVE_STARPU_DATA_SET_OOC_FLAGS )
            message("-- ${Blue}Add definition HAVE_STARPU_DATA_SET_OOC_FLAGS${ColourReset}")
        endif()
660 661 662 663
        check_function_exists(starpu_mpi_init_conf HAVE_STARPU_MPI_INIT_CONF)
        if ( HAVE_STARPU_MPI_INIT_CONF )
            message("-- ${Blue}Add definition HAVE_STARPU_MPI_INIT_CONF${ColourReset}")
        endif()
664 665
        check_function_exists(starpu_mpi_data_migrate HAVE_STARPU_MPI_DATA_MIGRATE)
        if ( HAVE_STARPU_MPI_DATA_MIGRATE )
666 667 668
            message("-- ${Blue}Add definition HAVE_STARPU_MPI_DATA_MIGRATE${ColourReset}")
        elseif(CHAMELEON_USE_MIGRATE)
            set(CHAMELEON_USE_MIGRATE "OFF")
669
            message("-- ${Blue}CHAMELEON_USE_MIGRATE is turned OFF because starpu_mpi_data_migrate not found${ColourReset}")
670
        endif()
671 672
        if(CHAMELEON_ENABLE_TRACING)
            # check if fxt profiling is accessible in starpu and activate it in chameleon
673 674
            check_function_exists(starpu_fxt_start_profiling HAVE_STARPU_FXT_PROFILING)
            if ( HAVE_STARPU_FXT_PROFILING )
675 676 677 678 679 680
                message("-- ${Blue}Add definition HAVE_STARPU_FXT_PROFILING"
                " - Activate FxT profiling through StarPU${ColourReset}")
            else()
                message("-- ${Red}Looking for starpu with fxt"
                " - starpu_fxt_start_profiling() test fails in StarPU${ColourReset}")
                message("-- ${Red}Check in CMakeFiles/CMakeError.log to figure out why it fails${ColourReset}")
681
            endif()
682 683 684
        endif()
        if (CHAMELEON_USE_MPI)
            # Check if a specific function exist
685 686
            check_function_exists(starpu_mpi_data_register_comm HAVE_STARPU_MPI_DATA_REGISTER)
            if ( HAVE_STARPU_MPI_DATA_REGISTER )
687 688
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_DATA_REGISTER - Activate"
                " use of starpu_mpi_data_register() in Chameleon with StarPU${ColourReset}")
689
            endif()
690 691
            check_function_exists(starpu_mpi_comm_rank HAVE_STARPU_MPI_COMM_RANK)
            if ( HAVE_STARPU_MPI_COMM_RANK )
692 693
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_COMM_RANK - Activate"
                " use of starpu_mpi_comm_rank() in Chameleon with StarPU${ColourReset}")
694
            endif()
695 696
            check_function_exists(starpu_mpi_cached_receive HAVE_STARPU_MPI_CACHED_RECEIVE)
            if ( HAVE_STARPU_MPI_CACHED_RECEIVE )
PRUVOST Florent's avatar
PRUVOST Florent committed
697 698
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_CACHED_RECEIVE${ColourReset}")
            endif()
699 700
            check_function_exists(starpu_mpi_comm_get_attr HAVE_STARPU_MPI_COMM_GET_ATTR)
            if ( HAVE_STARPU_MPI_COMM_GET_ATTR )
Mathieu Faverge's avatar
Mathieu Faverge committed
701 702
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_COMM_GET_ATTR${ColourReset}")
            endif()
703 704
        endif()
    else ( STARPU_FOUND )
705
        if(CHAMELEON_VERBOSE_FIND_PACKAGE)
706 707 708 709 710 711 712
            if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
                if (NOT HWLOC_hwloc.h_DIRS)
                    Print_Find_Header_Status(hwloc hwloc.h)
                endif ()
                if (NOT HWLOC_hwloc_LIBRARY)
                    Print_Find_Library_Status(hwloc libhwloc)
                endif ()
713
            endif()
714 715 716 717 718 719
            if(CHAMELEON_ENABLE_TRACING AND (NOT FXT_FOUND OR NOT FXT_LIBRARIES))
                if (NOT FXT_fxt.h_DIRS)
                    Print_Find_Header_Status(fxt fxt.h)
                endif ()
                if (NOT FXT_fxt_LIBRARY)
                    Print_Find_Library_Status(fxt libfxt)
720
                endif ()
721
            endif()
722
            if(CHAMELEON_SIMULATION AND (NOT SIMGRID_FOUND OR NOT SIMGRID_LIBRARIES))
723 724 725 726 727 728
                if (NOT SIMGRID_simgrid.h_DIRS)
                    Print_Find_Header_Status(simgrid simgrid.h)
                endif ()
                if (NOT SIMGRID_simgrid_LIBRARY)
                    Print_Find_Library_Status(simgrid libsimgrid)
                endif ()
729 730 731 732
            endif()
            if( (NOT STARPU_SHM_FOUND) OR (NOT STARPU_SHM_LIBRARIES) OR
                ( STARPU_LOOK_FOR_MPI AND (NOT STARPU_MPI_FOUND OR NOT STARPU_MPI_LIBRARIES) )
              )
733 734 735 736 737 738 739 740 741 742 743 744 745
                foreach(starpu_hdr ${STARPU_hdrs_to_find})
                    if (NOT STARPU_${starpu_hdr}_INCLUDE_DIRS)
                        Print_Find_Header_Status(starpu ${starpu_hdr})
                    endif ()
                endforeach()
                if(STARPU_VERSION_STRING)
                    foreach(starpu_lib ${STARPU_libs_to_find})
                        if (NOT STARPU_${starpu_lib}_LIBRARY)
                            Print_Find_Library_Status(starpu ${starpu_lib})
                        endif ()
                    endforeach()
                endif ()
            endif ()
746 747 748 749
        else(CHAMELEON_VERBOSE_FIND_PACKAGE)
            message(WARNING "StarPU library has not been found and CHAMELEON_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate CHAMELEON_VERBOSE_FIND_PACKAGE option (-DCHAMELEON_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
        endif(CHAMELEON_VERBOSE_FIND_PACKAGE)
750 751
        if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
            message(FATAL_ERROR "hwloc library is required but has not been found")
752
        endif()
753 754
        if(CHAMELEON_SIMULATION AND (NOT SIMGRID_FOUND OR NOT SIMGRID_LIBRARIES))
            message(FATAL_ERROR "SimGrid library is required but has not been found")
755
        endif()
756 757 758 759 760 761 762 763 764
        if(CHAMELEON_ENABLE_TRACING AND (NOT FXT_FOUND OR NOT FXT_LIBRARIES))
            message(FATAL_ERROR "FxT library is required but has not been found")
        endif()
        if( (NOT STARPU_SHM_FOUND) OR (NOT STARPU_SHM_LIBRARIES) OR
            ( STARPU_LOOK_FOR_MPI AND (NOT STARPU_MPI_FOUND OR NOT STARPU_MPI_LIBRARIES) )
          )
            message(FATAL_ERROR "StarPU library is required but has not been found")
        endif()
    endif ( STARPU_FOUND )
765

766
endif( CHAMELEON_SCHED_STARPU )
767

768
if( CHAMELEON_SCHED_PARSEC )
769

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
    # create list of components in order to make a single call to find_package(starpu...)
    set(PARSEC_COMPONENT_LIST "HWLOC")
    if(CHAMELEON_USE_MPI)
        list(APPEND PARSEC_COMPONENT_LIST "MPI")
    endif()
    if(CHAMELEON_USE_CUDA)
        list(APPEND PARSEC_COMPONENT_LIST "CUDA")
    endif()
    # TODO: Add a CHAMELEON_WITH_PROFILING option that enables Fxt for StarPU, or PAPI for PaRSEC
    #if(CHAMELEON_WITH_PROFILING)
    #    list(APPEND PARSEC_COMPONENT_LIST "PAPI")
    #endif()
    find_package(PARSEC COMPONENTS ${PARSEC_COMPONENT_LIST})
    if(PARSEC_FOUND)
        message("-- ${Blue}Add definition CHAMELEON_SCHED_PARSEC"
        " - Activate PaRSEC in Chameleon${ColourReset}")
786 787
      if (PARSEC_INCLUDE_DIRS_DEP)
          include_directories(${PARSEC_INCLUDE_DIRS_DEP})
788
      endif()
789
      if(PARSEC_CFLAGS_OTHER_DEP)
790
          set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PARSEC_CFLAGS_OTHER_DEP}")
791
          string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
792 793
      endif()
      if(PARSEC_LDFLAGS_OTHER_DEP)
794
          set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PARSEC_LDFLAGS_OTHER_DEP}")
795
          string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
796
      endif()
797
      if(PARSEC_LIBRARY_DIRS_DEP)
798 799
          list(APPEND CMAKE_INSTALL_RPATH "${PARSEC_LIBRARY_DIRS_DEP}")
      endif()
800 801
      if (PARSEC_LIBRARIES_DEP)
          list(INSERT CHAMELEON_DEP 0 ${PARSEC_LIBRARIES_DEP})
802
      endif()
803 804 805 806 807 808 809
      string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
      # to test if symbols exist, e.g.
      # set(CMAKE_REQUIRED_INCLUDES "${PARSEC_INCLUDE_DIRS_DEP}")
      # set(CMAKE_REQUIRED_FLAGS "${PARSEC_CFLAGS_OTHER_DEP}")
      # set(CMAKE_REQUIRED_LDFLAGS "${PARSEC_LDFLAGS_OTHER_DEP}")
      # set(CMAKE_REQUIRED_LIBRARIES "${PARSEC_LIBRARIES_DEP}")
      # check_function_exists(parsec_init HAVE_PARSEC_INIT)
810
    else ( PARSEC_FOUND )
811
        if(CHAMELEON_VERBOSE_FIND_PACKAGE)
812 813 814 815 816 817 818 819 820 821 822 823
            if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
                if (NOT HWLOC_hwloc.h_DIRS)
                    Print_Find_Header_Status(hwloc hwloc.h)
                endif ()
                if (NOT HWLOC_hwloc_LIBRARY)
                    Print_Find_Library_Status(hwloc libhwloc)
                endif ()
            endif()
            if( (NOT PARSEC_FOUND) OR (NOT PARSEC_LIBRARIES_DEP) )
              foreach(parsec_hdr ${PARSEC_hdrs_to_find})
                    if (NOT PARSEC_${parsec_hdr}_INCLUDE_DIRS)
                        Print_Find_Header_Status(parsec ${parsec_hdr})
824
                    endif ()
825 826 827 828 829
                endforeach()
                if(PARSEC_VERSION_STRING)
                    foreach(parsec_lib ${PARSEC_libs_to_find})
                        if (NOT PARSEC_${parsec_lib}_LIBRARY)
                            Print_Find_Library_Status(parsec ${parsec_lib})
830 831 832 833
                        endif ()
                    endforeach()
                endif()
            endif()
834 835 836 837
        else(CHAMELEON_VERBOSE_FIND_PACKAGE)
            message(WARNING "PaRSEC library has not been found and CHAMELEON_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate CHAMELEON_VERBOSE_FIND_PACKAGE option (-DCHAMELEON_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
        endif(CHAMELEON_VERBOSE_FIND_PACKAGE)
838 839 840 841 842 843 844
        if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
            message(FATAL_ERROR "hwloc library is required but has not been found")
        endif()
        if( (NOT PARSEC_FOUND) OR (NOT PARSEC_LIBRARIES_DEP) )
            message(FATAL_ERROR "PaRSEC library is required but has not been found")
        endif()
    endif ( PARSEC_FOUND )
845

846
endif( CHAMELEON_SCHED_PARSEC )
847

848 849
      # try to find quark runtime
if( CHAMELEON_SCHED_QUARK )
850

851
    find_package(QUARK COMPONENTS HWLOC)
852

853 854 855 856
    # Add definition and include_dir if found
    if(QUARK_FOUND)
        message("-- ${Blue}Add definition CHAMELEON_SCHED_QUARK"
        " - Activate QUARK in Chameleon${ColourReset}")
857 858 859 860
        if (QUARK_INCLUDE_DIRS_DEP)
            include_directories(${QUARK_INCLUDE_DIRS_DEP})
        endif()
        if(QUARK_CFLAGS_OTHER_DEP)
861
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${QUARK_CFLAGS_OTHER_DEP}")
862
            string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
863 864
        endif()
        if(QUARK_LDFLAGS_OTHER_DEP)
865
            set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${QUARK_LDFLAGS_OTHER_DEP}")
866
            string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
867 868 869 870 871 872
        endif()
        if(QUARK_LIBRARY_DIRS_DEP)
            list(APPEND CMAKE_INSTALL_RPATH "${QUARK_LIBRARY_DIRS_DEP}")
        endif()
        if (QUARK_LIBRARIES_DEP)
            list(INSERT CHAMELEON_DEP 0 ${QUARK_LIBRARIES_DEP})
873 874
        endif()
    else(QUARK_FOUND)
875
        if(CHAMELEON_VERBOSE_FIND_PACKAGE)
876
            if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
877 878 879 880 881 882
                if (NOT HWLOC_hwloc.h_DIRS)
                    Print_Find_Header_Status(hwloc hwloc.h)
                endif ()
                if (NOT HWLOC_hwloc_LIBRARY)
                    Print_Find_Library_Status(hwloc libhwloc)
                endif ()
883
            endif()
884 885 886 887 888 889 890
            if (NOT QUARK_quark.h_DIRS)
                Print_Find_Header_Status(quark quark.h)
            endif ()
            if (NOT QUARK_quark_LIBRARY)
                Print_Find_Library_Status(quark libquark)
            endif ()
        else()
891 892
            message(WARNING "QUARK library has not been found and CHAMELEON_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate CHAMELEON_VERBOSE_FIND_PACKAGE option (-DCHAMELEON_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
893 894 895 896 897 898
        endif()
        if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
            message(FATAL_ERROR "hwloc library is required but has not been found")
        endif()
        message(FATAL_ERROR "QUARK library is required but has not been found")
    endif(QUARK_FOUND)
899

900
endif()
901

902
if( CHAMELEON_SCHED_OPENMP )
Philippe Virouleau's avatar
Philippe Virouleau committed
903
    find_package(OpenMP REQUIRED)
904 905 906 907

    if ( OPENMP_FOUND )
        message("-- ${Blue}Add definition CHAMELEON_SCHED_OPENMP"
        " - Activate OpenMP in Chameleon${ColourReset}")
908
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
Philippe Virouleau's avatar
Philippe Virouleau committed
909 910
        set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}")
Philippe Virouleau's avatar
Philippe Virouleau committed
911
        # TODO: check for compiler support for "_Pragma"
912
    else ( OPENMP_FOUND )
913
      message(FATAL_ERROR "Something went wrong when finding OpenMP")
914 915 916 917
    endif ( OPENMP_FOUND )

endif( CHAMELEON_SCHED_OPENMP )

918 919
# getopt
check_include_files(getopt.h CHAMELEON_HAVE_GETOPT_H)
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
920 921 922
if (CHAMELEON_HAVE_GETOPT_H)
  check_function_exists(getopt_long CHAMELEON_HAVE_GETOPT_LONG)
endif()
923

924 925 926 927 928 929
# Add option to exploit cublas API v2
# -----------------------------------
cmake_dependent_option(CHAMELEON_USE_CUBLAS_V2
  "Enable cublas API v2" ON
  "CHAMELEON_USE_CUDA;CHAMELEON_SCHED_STARPU" OFF)

930 931
list(REMOVE_DUPLICATES CMAKE_C_FLAGS)
string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
932 933 934 935 936 937
list(REMOVE_DUPLICATES CMAKE_EXE_LINKER_FLAGS)
string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
# Fix a problem on Mac OS X when building shared libraries
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
endif()
938

939 940
# Save extra dependencies (all required links)
list(APPEND CHAMELEON_DEP ${EXTRA_LIBRARIES})
941
# We remove duplicate dependencies ensuring that redundant libraries are placed last
942
list(REVERSE CHAMELEON_DEP)
943
list(REMOVE_DUPLICATES CHAMELEON_DEP)
944
list(REVERSE CHAMELEON_DEP)
945

PRUVOST Florent's avatar
PRUVOST Florent committed
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
# we add chameleon's own library
set(CHAMELEON_LIBRARIES "chameleon")
if (NOT CHAMELEON_SIMULATION)
  list(APPEND CHAMELEON_LIBRARIES coreblas)
  if (CHAMELEON_USE_CUDA)
    list(APPEND CHAMELEON_LIBRARIES cudablas)
  endif()
endif()
if (CHAMELEON_SCHED_QUARK)
  list(APPEND CHAMELEON_LIBRARIES chameleon_quark)
endif()
if (CHAMELEON_SCHED_PARSEC)
  list(APPEND CHAMELEON_LIBRARIES chameleon_parsec)
endif()
if (CHAMELEON_SCHED_STARPU)
  list(APPEND CHAMELEON_LIBRARIES chameleon_starpu)
endif()
963 964 965
if (CHAMELEON_SCHED_OPENMP)
  list(APPEND CHAMELEON_LIBRARIES chameleon_openmp)
endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
966 967 968
list(APPEND CHAMELEON_LIBRARIES hqr)
set(CHAMELEON_LIBRARIES_DEP ${CHAMELEON_LIBRARIES} ${CHAMELEON_DEP})

969 970
# Check for the subdirectories
# ----------------------------
971

972 973
set(CHAMELEON_SOURCES_TARGETS "" CACHE INTERNAL "List of targets of sources")

974 975 976 977 978 979
# include headers
# ---------------
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
980

981 982 983 984 985 986 987 988 989 990 991 992
if (NOT CHAMELEON_SIMULATION)
  ###############################################################################
  # Coreblas library (kernels for CPUs) #
  #######################################
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/coreblas/include)
  include_directories(${CMAKE_CURRENT_BINARY_DIR}/coreblas/include)
  add_subdirectory(coreblas)

  ###############################################################################
  # Cudablas library (kernels for CUDAs) #
  ########################################
  if(CHAMELEON_USE_CUDA)
993 994
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/cudablas/include)
    include_directories(${CMAKE_CURRENT_BINARY_DIR}/cudablas/include)
995
    add_subdirectory(cudablas)
996 997
  endif()

998
endif()
999

1000
###############################################################################
1001 1002 1003 1004 1005
# Main library #
################
add_subdirectory(include)
add_subdirectory(control)
add_subdirectory(compute)
1006

1007
###############################################################################
1008 1009
# Runtimes libraries #
######################
1010
add_subdirectory(runtime)
1011

1012 1013 1014 1015 1016
###############################################################################
# Executables and Tests #
#########################
enable_testing()
include(CTest)
1017

1018 1019 1020 1021 1022 1023 1024
# Necessary to compile executables (temporary)
# should use SystemDetection.cmake module?
string(REGEX MATCH ".*ifort$" _match_ifort ${CMAKE_Fortran_COMPILER})
if(_match_ifort)
    message(STATUS "Add -nofor_main to the Fortran linker (Intel compiler)")
    set(CMAKE_Fortran_FLAGS  "${CMAKE_Fortran_FLAGS} -nofor_main")
endif(_match_ifort)
1025

1026
# Testing executables
1027
if(CHAMELEON_ENABLE_EXAMPLE AND NOT CHAMELEON_SIMULATION)
1028
  add_subdirectory(example)
1029
endif(CHAMELEON_ENABLE_EXAMPLE AND NOT CHAMELEON_SIMULATION)
1030

1031
# Testing executables
1032
if(CHAMELEON_ENABLE_TESTING AND NOT CHAMELEON_SIMULATION)
1033
  add_subdirectory(testing)
1034
endif(CHAMELEON_ENABLE_TESTING AND NOT CHAMELEON_SIMULATION)
1035

1036 1037 1038 1039 1040
# Timing executables
if(CHAMELEON_ENABLE_TIMING)
  add_subdirectory(timing)
endif(CHAMELEON_ENABLE_TIMING)
#------------------------------------------------------------------------------
1041

1042 1043 1044
# Define a target which gathers all targets of sources
# useful for generating the doc without compiling the binaries (objects, libraries)
add_custom_target(chameleon_all_sources ALL DEPENDS ${CHAMELEON_SOURCES_TARGETS})
1045

1046 1047 1048
###############################################################################
# Documentation #
#################
1049

1050 1051
if(CHAMELEON_ENABLE_DOC)
    add_subdirectory(doc)
1052 1053
    if (DOXYGEN_EXECUTABLE AND EMACS_COMPILER AND TEX_COMPILER)
        add_custom_target(doc ALL DEPENDS doxygen-out doc-html-users_guide doc-pdf-users_guide)
1054
    endif()
1055 1056
endif()
#------------------------------------------------------------------------------
1057

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070

###############################################################################
# Make cmake include starpu_simgrid_wrap.h (which #define main and thus makes #
# link tests fail) only after tests.                                          #
###############################################################################
if( CHAMELEON_SCHED_STARPU )
    if ( STARPU_FOUND )
        if (CHAMELEON_SIMULATION)
            list(APPEND CMAKE_REQUIRED_FLAGS "-include" "starpu_simgrid_wrap.h")
        endif()
    endif()
endif()

1071 1072 1073
###############################################################################
# Config files (pkg_config) #
#############################
1074

1075
# Create .pc file
1076
# ---------------
1077
generate_pkgconfig_file()
1078 1079 1080 1081 1082 1083 1084
#------------------------------------------------------------------------------

###############################################################################
# Release source #
##################
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_PACKAGE_NAME "chameleon")
1085
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.org)
1086 1087 1088 1089
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Chameleon is a C library providing parallel algorithms to perform BLAS/LAPACK "
                                      " operations exploiting fully modern architectures.")
set(CHAMELEON_VERSION_PATCH ${CHAMELEON_VERSION_MICRO})
set(CPACK_PACKAGE_VERSION "${CHAMELEON_VERSION_MAJOR}.${CHAMELEON_VERSION_MINOR}.${CHAMELEON_VERSION_PATCH}")
1090
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
1091 1092 1093
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_PACKAGE_VENDOR "Inria")
set(CPACK_PACKAGE_CONTACT "morse-devel@lists.gforge.inria.fr")
1094
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.org)
1095 1096
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENCE.txt)
set(CPACK_SOURCE_IGNORE_FILES "plasma-conversion;build;.cproject;.settings;.dir-locals.el;.project;.pydevproject;.svn;.git;.gitmodules;.gitlab-ci.yml")
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
include(CPack)

###############################################################################
# Print Options #
#################
include(PrintOpts)

if (CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR CMAKE_INSTALL_PREFIX STREQUAL "C:/Program Files")
    message("-- ${Yellow}Your CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX} which is a default system path."
    " You may want to change it: set the CMAKE_INSTALL_PREFIX variable to do so${ColourReset}")
else()
    message("-- ${Yellow}Your CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX}${ColourReset}")
endif()
1110

1111 1112 1113
###
### END CMakeLists.txt
###