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

# 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
40 41
set(CHAMELEON_VERSION_MAJOR 0)
set(CHAMELEON_VERSION_MINOR 9)
42
set(CHAMELEON_VERSION_MICRO 1)
43

44 45 46 47
set(MORSE_CMAKE_DIR "" CACHE PATH "Directory of MORSE CMake modules, can be external to the project")

# Add extra cmake module path and initialize morse cmake modules
# --------------------------------------------------------------
48
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
49
if(MORSE_CMAKE_DIR)
50 51
    list(APPEND CMAKE_MODULE_PATH "${MORSE_CMAKE_DIR}/cmake_modules/morse_cmake/modules")
    set(MORSE_CMAKE_MODULE_PATH ${MORSE_CMAKE_DIR}/cmake_modules/morse_cmake/modules )
52
elseif(EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake")
53 54
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules")
    set(MORSE_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules )
55 56 57 58 59 60 61
else()
  message(FATAL_ERROR "Chameleon CMake system relies on morse_cmake modules developed here: "
    "https://gitlab.inria.fr/solverstack/morse_cmake. Please set MORSE_CMAKE_DIR to this source "
    "directory.")
endif()
include(MorseInit)
include(GenPkgConfig)
62
include(FortranCInterface)
PRUVOST Florent's avatar
PRUVOST Florent committed
63 64
# Ensure that the fortran compiler and c compiler specified are compatible
# ------------------------------------------------------------------------
65 66 67
FortranCInterface_VERIFY()
FortranCInterface_HEADER(${CMAKE_CURRENT_BINARY_DIR}/include/morse_mangling.h
                         MACRO_NAMESPACE "MORSE_")
68 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

#############################################
#                                           #
#        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
# -----------------------------------------
set( RP_CHAMELEON_DICTIONNARY ${MORSE_CMAKE_MODULE_PATH}/precision_generator/subs.py )
set( RP_CHAMELEON_PRECISIONS  "s;d;c;z" )
include(RulesPrecisions)

# Options to select the runtime
# -----------------------------

# Create a list of possible runtime
set(CHAMELEON_SCHED_list "PARSEC" "STARPU" "QUARK")

# Initially PaRSEC runtime is enabled
option(CHAMELEON_SCHED_PARSEC
    "Enable PaRSEC scheduler as the default runtime
    (Conflict with other CHAMELEON_SCHED_* options)" OFF)
option(CHAMELEON_SCHED_STARPU
    "Enable StarPU scheduler as the default runtime
    (Conflict with other CHAMELEON_SCHED_* options)" OFF)
option(CHAMELEON_SCHED_QUARK
    "Enable Quark scheduler as the default runtime
    (Conflict with other CHAMELEON_SCHED_* options)" OFF)

# For now, we are able to compile only one runtime at a time, so we disable combinations of runtimes
if (CHAMELEON_SCHED_QUARK)
    set(CHAMELEON_SCHED_STARPU OFF)
    set(CHAMELEON_SCHED_PARSEC OFF)
elseif (CHAMELEON_SCHED_STARPU)
    set(CHAMELEON_SCHED_QUARK OFF)
    set(CHAMELEON_SCHED_PARSEC OFF)
elseif (CHAMELEON_SCHED_PARSEC)
    set(CHAMELEON_SCHED_QUARK OFF)
    set(CHAMELEON_SCHED_STARPU OFF)
endif()
# Set default to StarPU if nothing specific is required by the user
if ( NOT CHAMELEON_SCHED_STARPU AND NOT CHAMELEON_SCHED_PARSEC AND NOT CHAMELEON_SCHED_QUARK )
    set(CHAMELEON_SCHED_STARPU ON)
endif()
if (CHAMELEON_SCHED_STARPU)
    message("-- ${BoldGreen}CHAMELEON_SCHED_STARPU is set to ON: CHAMELEON uses StarPU runtime\n"
            "   To use CHAMELEON with Quark  runtime: set CHAMELEON_SCHED_QUARK  to ON\n"
            "   To use CHAMELEON with PaRSEC runtime: set CHAMELEON_SCHED_PARSEC to ON\n"
            "   (CHAMELEON_SCHED_STARPU will be disabled)${ColourReset}")
elseif(CHAMELEON_SCHED_QUARK)
    message("-- ${BoldGreen}CHAMELEON_SCHED_QUARK is set to ON: CHAMELEON uses Quark runtime\n"
            "   To use CHAMELEON with StarPU runtime: set CHAMELEON_SCHED_STARPU to ON\n"
            "   To use CHAMELEON with PaRSEC runtime: set CHAMELEON_SCHED_PARSEC to ON\n"
            "   (CHAMELEON_SCHED_QUARK will be disabled)${ColourReset}")
elseif(CHAMELEON_SCHED_PARSEC)
    message("-- ${BoldGreen}CHAMELEON_SCHED_PARSEC is set to ON: CHAMELEON uses PaRSEC runtime\n"
            "   To use CHAMELEON with StarPU runtime: set CHAMELEON_SCHED_STARPU to ON\n"
            "   To use CHAMELEON with Quark  runtime: set CHAMELEON_SCHED_QUARK  to ON\n"
            "   (CHAMELEON_SCHED_PARSEC will be disabled)${ColourReset}")
endif()
151

152 153 154 155 156 157
# 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")
158
    endif()
159 160 161 162 163 164
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()
165

166 167 168 169 170
# 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()
171

172 173 174 175 176
# 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()
177

178 179
# Additional options
# ------------------
180

181 182 183 184 185 186 187 188
# 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()
189

190 191 192 193 194 195 196 197
# 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()
198

199 200 201 202 203 204
# 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)
205

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
# Options to enable/disable testings and timings
# ----------------------------------------------
option(CHAMELEON_ENABLE_DOCS     "Enable documentation build"  OFF)
if (CHAMELEON_ENABLE_DOCS)
    message("-- ${BoldGreen}CHAMELEON_ENABLE_DOCS is set to ON, turn it OFF to avoid building docs${ColourReset}")
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()
224

225 226 227 228 229 230 231
# 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}")
232
    endif()
233 234 235 236 237 238 239
    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)
240
endif()
241

242 243 244 245 246 247 248 249 250 251 252
# 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)
#------------------------------------------------------------------------------


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

253
set(CHAMELEON_USE_LIBHQR 1)
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
254 255 256 257
find_package(LIBHQR REQUIRED)
list(INSERT CHAMELEON_DEP 0 ${LIBHQR_LIBRARIES})
include_directories(${LIBHQR_INCLUDE_DIRS})

258 259 260 261 262
# Check for Thread library
# ------------------------
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
if( THREADS_FOUND )
263
  list(APPEND EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
264 265 266 267 268 269 270
endif ()

# Add math library to the list of extra
# it normally exists on all common systems provided with a C compiler
set(M_LIBRARIES "")
if(UNIX OR WIN32)
    find_library(
271 272 273
      M_m_LIBRARY
      NAMES m
      )
274 275
    mark_as_advanced(M_m_LIBRARY)
    if (M_m_LIBRARY)
276 277
      list(APPEND M_LIBRARIES "${M_m_LIBRARY}")
      list(APPEND EXTRA_LIBRARIES "${M_m_LIBRARY}")
278
    else()
279 280
      message(FATAL_ERROR "Could NOT find libm on your system."
        " Are you sure to a have a C compiler installed?")
281
    endif()
282
endif()
283

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
# Try to find librt (libposix4 - POSIX.1b Realtime Extensions library)
# on Unix systems except Apple ones because it does not exist on it
set(RT_LIBRARIES "")
if(UNIX AND NOT APPLE)
    find_library(
        RT_rt_LIBRARY
        NAMES rt
        )
    mark_as_advanced(RT_rt_LIBRARY)
    if (RT_rt_LIBRARY)
        list(APPEND RT_LIBRARIES "${RT_rt_LIBRARY}")
        list(APPEND EXTRA_LIBRARIES "${RT_rt_LIBRARY}")
    else()
        message(FATAL_ERROR "Could NOT find librt on your system")
    endif()
endif()
300

301 302 303
# If simulation we don't enter in kernel functions so that we don't need to
# link with concerned libraries
if(NOT CHAMELEON_SIMULATION)
304

305 306 307 308 309 310 311
    # CHAMELEON depends on CBLAS
    #---------------------------
    find_package(CBLAS COMPONENTS BLASEXT)
    if(BLAS_FOUND)
        if (BLAS_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${BLAS_LIBRARY_DIRS}")
312
        endif()
313 314
        if(BLAS_LINKER_FLAGS)
            list(APPEND CMAKE_EXE_LINKER_FLAGS "${BLAS_LINKER_FLAGS}")
315
        endif()
316 317
    else()
        message(FATAL_ERROR "BLAS library has not been found")
318
    endif()
319 320 321 322 323 324 325 326 327 328 329
    if(CBLAS_FOUND)
        include_directories(${CBLAS_INCLUDE_DIRS})
        if(CBLAS_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${CBLAS_LIBRARY_DIRS}")
        endif()
        if (CBLAS_LIBRARIES)
            if (CBLAS_LIBRARIES_DEP)
                list(INSERT CHAMELEON_DEP 0 ${CBLAS_LIBRARIES_DEP})
            else()
                list(INSERT CHAMELEON_DEP 0 ${CBLAS_LIBRARIES})
330
            endif()
331 332 333 334 335 336 337 338 339 340
        endif()
    else()
        if(MORSE_VERBOSE_FIND_PACKAGE)
            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 ()
341
            endif()
342
        else()
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
            message(WARNING "CBLAS library has not been found and MORSE_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate MORSE_VERBOSE_FIND_PACKAGE option (-DMORSE_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
        endif()
        message(FATAL_ERROR "A CBLAS library is required but has not been found")
    endif()

    # CHAMELEON depends on LAPACKE
    #-----------------------------
    # standalone version of lapacke seems useless for now
    # let the comment in case we meet some problems of non existing lapacke
    # functions in lapack library such as mkl, acml, ...
    #set(LAPACKE_STANDALONE TRUE)
    find_package(LAPACKE COMPONENTS LAPACKEXT)
    if(LAPACK_FOUND AND LAPACK_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${LAPACK_LIBRARY_DIRS}")
    else()
        message(FATAL_ERROR "A LAPACK library is required but has not been found")
    endif()
    if(LAPACKE_FOUND)
        include_directories(${LAPACKE_INCLUDE_DIRS})
        if(LAPACKE_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${LAPACKE_LIBRARY_DIRS}")
        endif()
        if(LAPACKE_LINKER_FLAGS)
            list(APPEND CMAKE_EXE_LINKER_FLAGS "${LAPACKE_LINKER_FLAGS}")
370
        endif()
371 372 373 374 375
        if (LAPACKE_LIBRARIES)
            if (LAPACKE_LIBRARIES_DEP)
                list(INSERT CHAMELEON_DEP 0 ${LAPACKE_LIBRARIES_DEP})
            else()
                list(INSERT CHAMELEON_DEP 0 ${LAPACKE_LIBRARIES})
376
            endif()
377 378 379 380 381 382 383 384 385 386
        endif()
    else()
        if(MORSE_VERBOSE_FIND_PACKAGE)
            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 ()
387
            endif()
388
        else()
389 390
            message(WARNING "LAPACKE library has not been found and MORSE_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate MORSE_VERBOSE_FIND_PACKAGE option (-DMORSE_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
391
        endif()
392 393
        message(FATAL_ERROR "A LAPACKE library is required but has not been found")
    endif()
394

395 396 397 398 399
    # CHAMELEON depends on TMG
    #-------------------------
    if (CHAMELEON_ENABLE_TESTING OR CHAMELEON_ENABLE_TIMING)
        find_package(TMG)
        if(TMG_FOUND AND TMG_LIBRARY_DIRS)
400
            # the RPATH to be used when installing
401
            list(APPEND CMAKE_INSTALL_RPATH "${TMG_LIBRARY_DIRS}")
402
        else()
403
            message(FATAL_ERROR "A TMG library is required but has not been found")
404
        endif()
405 406 407 408 409 410
        if(TMG_LINKER_FLAGS)
            list(APPEND CMAKE_EXE_LINKER_FLAGS "${TMG_LINKER_FLAGS}")
        endif()
        if (TMG_LIBRARIES)
            if (TMG_LIBRARIES_DEP)
                list(INSERT CHAMELEON_DEP 0 ${TMG_LIBRARIES_DEP})
411
            else()
412
                list(INSERT CHAMELEON_DEP 0 ${TMG_LIBRARIES})
413
            endif()
414
        endif()
415 416 417 418 419
    endif()

    # CHAMELEON depends on CUDA/CUBLAS
    #----------------------------------
    if (CHAMELEON_USE_CUDA)
420

421 422 423 424 425 426
        find_package(CUDA REQUIRED)

        if (CUDA_FOUND)
            message("-- ${Blue}Add definition CHAMELEON_USE_CUDA"
            " - Activate CUDA in Chameleon${ColourReset}")
            set(EXTRA_LIBRARIES_CUDA)
427
            set(CHAMELEON_USE_CUDA 1)
428 429 430 431 432 433
            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})
434
            else()
435 436 437
                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.")
438
            endif()
439 440 441 442 443 444 445 446
            if (CUDA_LIBRARIES)
                list(APPEND EXTRA_SOURCES src/gpu_data.c)
                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)
447
                else()
448
                    check_function_exists(cuDeviceCanAccessPeer CUDA_HAVE_PEER_DEVICE_MEMORY_ACCESS)
449
                endif()
450 451 452 453 454 455
                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}")
456
                    set( CHAMELEON_USE_CUBLAS 1)
457 458
                    list(APPEND EXTRA_LIBRARIES_CUDA ${CUDA_CUBLAS_LIBRARIES})
                    list(APPEND EXTRA_LIBRARIES_CUDA ${CUDA_LIBRARIES}) # need CUDA libs to link.
459 460
                else()
                    message(FATAL_ERROR "CHAMELEON_USE_CUDA requires"
461 462
                    "\n   CUDA_CUBLAS_LIBRARIES to be found. Be sure you have"
                    "\n   libcublas with your distribution of CUDA.")
463
                endif()
464 465 466 467
            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.")
468
            endif()
469 470
            #FindHeader(CUDA cublas_v2.h)
            #if(CUDA_cublas_v2.h_DIRS)
471
                #set(CHAMELEON_USE_CUBLAS_V2 1)
472 473 474 475
            #endif()
        endif (CUDA_FOUND)

        list(APPEND EXTRA_LIBRARIES ${EXTRA_LIBRARIES_CUDA})
476

477
    endif(CHAMELEON_USE_CUDA)
478

479 480 481
    # CHAMELEON depends on MPI
    #-------------------------
    if (CHAMELEON_USE_MPI)
482

483 484 485 486 487
        # 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)
488
        endif()
489 490 491 492 493
        find_package(MPI REQUIRED)

        if (MPI_C_FOUND)
            message("-- ${Blue}Add definition CHAMELEON_USE_MPI"
            " - Activate MPI in Chameleon${ColourReset}")
494
            set(CHAMELEON_USE_MPI 1)
495 496 497 498 499 500 501
            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")
            if(MPI_C_LINK_FLAGS)
                list(APPEND CMAKE_EXE_LINKER_FLAGS "${MPI_C_LINK_FLAGS}")
502
            endif()
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
        endif (MPI_C_FOUND)

    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}")
521
    set(CHAMELEON_SIMULATION 1)
522 523 524 525 526 527

    add_subdirectory(simucore)

    # Guard against mis-used simulation mode
    if(NOT DEFINED CHAMELEON_USE_CUDA)
        message(FATAL_ERROR "${BoldBlue}"
528
        "In simulation mode CHAMELEON_USE_CUDA should be set to"
529 530 531
        "   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"
532
        "   else set CHAMELEON_USE_CUDA=OFF."
533 534
        "${ColourReset}")
    endif()
535

536 537
    # Add CUDA definition if required
    if (CHAMELEON_USE_CUDA)
538
        set(CHAMELEON_USE_CUDA 1)
539
    endif()
540

541 542 543 544
    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()
545

546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
    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}")
603
            set(CHAMELEON_USE_MPI 1)
604 605 606 607
            list(APPEND EXTRA_LIBRARIES ${MPI_C_LIBRARIES} )
            include_directories( ${MPI_C_INCLUDE_PATH} )
            if(MPI_C_LINK_FLAGS)
                list(APPEND CMAKE_EXE_LINKER_FLAGS "${MPI_C_LINK_FLAGS}")
608
            endif()
609
        endif (MPI_C_FOUND)
610

611
    endif (CHAMELEON_USE_MPI)
612

613
endif(NOT CHAMELEON_SIMULATION)
614 615


616 617
# CHAMELEON depends on a runtime
# -------------------------------
618

619
if( CHAMELEON_SCHED_STARPU )
620

621
  set(CHAMELEON_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
622

623 624 625 626 627
    # 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")
628
        endif()
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
    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}")
646
        set(CHAMELEON_SCHED_STARPU 1)
647 648 649
        include_directories(${STARPU_INCLUDE_DIRS_DEP})
        if(STARPU_LINKER_FLAGS)
            list(APPEND CMAKE_EXE_LINKER_FLAGS "${STARPU_LINKER_FLAGS}")
650
        endif()
651 652 653 654 655 656 657 658 659
        set(CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS_DEP}")
        foreach(libdir ${STARPU_LIBRARY_DIRS_DEP})
            list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}")
        endforeach()
        set(CMAKE_REQUIRED_LIBRARIES "${STARPU_LIBRARIES_DEP}")
        if (CHAMELEON_USE_MPI)
            list(APPEND CMAKE_REQUIRED_INCLUDES "${MPI_C_INCLUDE_PATH}")
            list(APPEND CMAKE_REQUIRED_FLAGS "${MPI_C_LINK_FLAGS}")
            list(APPEND CMAKE_REQUIRED_LIBRARIES "${MPI_C_LIBRARIES}")
660
        endif()
661 662 663 664 665 666
        if (CHAMELEON_SIMULATION)
            list(APPEND CMAKE_REQUIRED_FLAGS "-include" "starpu_simgrid_wrap.h")
        endif()
        string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
        check_function_exists(starpu_data_idle_prefetch_on_node STARPU_IDLE_PREFETCH_FOUND)
        if ( STARPU_IDLE_PREFETCH_FOUND )
667 668
            set(HAVE_STARPU_IDLE_PREFETCH 1)
            message("-- ${Blue}Add definition HAVE_STARPU_IDLE_PREFETCH${ColourReset}")
669
        endif()
670 671 672 673
        check_function_exists(starpu_iteration_push STARPU_ITERATION_PUSH_FOUND)
        if ( STARPU_ITERATION_PUSH_FOUND )
            set(HAVE_STARPU_ITERATION_PUSH 1)
            message("-- ${Blue}Add definition HAVE_STARPU_ITERATION_PUSH${ColourReset}")
674
        endif()
675 676
        check_function_exists(starpu_data_wont_use STARPU_DATA_WONT_USE_FOUND)
        if ( STARPU_DATA_WONT_USE_FOUND )
677 678
            set(HAVE_STARPU_DATA_WONT_USE 1)
            message("-- ${Blue}Add definition HAVE_STARPU_DATA_WONT_USE${ColourReset}")
679
        endif()
680 681 682 683 684
        check_function_exists(starpu_data_set_coordinates STARPU_DATA_SET_COORDINATES_FOUND)
        if ( STARPU_DATA_SET_COORDINATES_FOUND )
            set(HAVE_STARPU_DATA_SET_COORDINATES 1)
            message("-- ${Blue}Add definition HAVE_STARPU_DATA_SET_COORDINATES${ColourReset}")
        endif()
685 686
        check_function_exists(starpu_malloc_on_node_set_default_flags STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS)
        if ( STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS )
687 688
            set(HAVE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS 1)
            message("-- ${Blue}Add definition HAVE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS${ColourReset}")
689 690 691 692 693 694 695 696
        endif()
        if(CHAMELEON_ENABLE_TRACING)
            # check if fxt profiling is accessible in starpu and activate it in chameleon
            unset(STARPU_FXT_START_PROFILING_FOUND CACHE)
            check_function_exists(starpu_fxt_start_profiling STARPU_FXT_START_PROFILING_FOUND)
            if ( STARPU_FXT_START_PROFILING_FOUND )
                message("-- ${Blue}Add definition HAVE_STARPU_FXT_PROFILING"
                " - Activate FxT profiling through StarPU${ColourReset}")
697
                set(HAVE_STARPU_FXT_PROFILING 1)
698 699 700 701
            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}")
702
            endif()
703 704 705 706 707 708 709 710
        endif()
        if (CHAMELEON_USE_MPI)
            # Check if a specific function exist
            unset(STARPU_MPI_DATA_REGISTER_FOUND CACHE)
            check_function_exists(starpu_mpi_data_register_comm STARPU_MPI_DATA_REGISTER_FOUND)
            if ( STARPU_MPI_DATA_REGISTER_FOUND )
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_DATA_REGISTER - Activate"
                " use of starpu_mpi_data_register() in Chameleon with StarPU${ColourReset}")
711
                set(HAVE_STARPU_MPI_DATA_REGISTER 1)
712 713 714 715
            else()
                message("-- ${Red}Looking for starpu with starpu_mpi_data_register"
                " - starpu_mpi_data_register() test fails in StarPU${ColourReset}")
                message("-- ${Red}Check in CMakeFiles/CMakeError.log to figure out why it fails${ColourReset}")
716
            endif()
717 718 719 720 721
            unset(STARPU_MPI_COMM_RANK_FOUND CACHE)
            check_function_exists(starpu_mpi_comm_rank STARPU_MPI_COMM_RANK_FOUND)
            if ( STARPU_MPI_COMM_RANK_FOUND )
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_COMM_RANK - Activate"
                " use of starpu_mpi_comm_rank() in Chameleon with StarPU${ColourReset}")
722
                set(HAVE_STARPU_MPI_COMM_RANK 1)
723 724 725 726
            else()
                message("-- ${Red}Looking for starpu with starpu_mpi_comm_rank"
                " - starpu_mpi_comm_rank() test fails in StarPU${ColourReset}")
                message("-- ${Red}Check in CMakeFiles/CMakeError.log to figure out why it fails${ColourReset}")
727
            endif()
728 729 730 731 732
	    check_function_exists(starpu_mpi_cached_receive STARPU_MPI_CACHED_RECEIVE)
	    if ( STARPU_MPI_CACHED_RECEIVE )
		set(HAVE_STARPU_MPI_CACHED_RECEIVE 1)
		message("-- ${Blue}Add definition HAVE_STARPU_MPI_CACHED_RECEIVE${ColourReset}")
	    endif()
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
        endif()
        if(HWLOC_FOUND AND HWLOC_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${HWLOC_LIBRARY_DIRS}")
        endif()
        if(FXT_FOUND AND FXT_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${FXT_LIBRARY_DIRS}")
        endif()
        if(SIMGRID_FOUND AND SIMGRID_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${SIMGRID_LIBRARY_DIRS}")
        endif()
        if(STARPU_FOUND AND STARPU_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${STARPU_LIBRARY_DIRS}")
        endif()
        if (STARPU_LIBRARIES)
            if (STARPU_LIBRARIES_DEP)
                list(INSERT CHAMELEON_DEP 0 ${STARPU_LIBRARIES_DEP})
            else()
                list(INSERT CHAMELEON_DEP 0 ${STARPU_LIBRARIES})
755
            endif()
756 757 758 759 760 761 762 763 764 765
        endif()
    else ( STARPU_FOUND )
        if(MORSE_VERBOSE_FIND_PACKAGE)
            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 ()
766
            endif()
767 768 769 770 771 772
            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)
Mathieu Faverge's avatar
Mathieu Faverge committed
773
                endif ()
774
            endif()
775
            if(CHAMELEON_SIMULATION AND (NOT SIMGRID_FOUND OR NOT SIMGRID_LIBRARIES))
776 777 778 779 780 781
                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 ()
782 783 784 785
            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) )
              )
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
                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 ()
        else(MORSE_VERBOSE_FIND_PACKAGE)
            message(WARNING "StarPU library has not been found and MORSE_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate MORSE_VERBOSE_FIND_PACKAGE option (-DMORSE_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
        endif(MORSE_VERBOSE_FIND_PACKAGE)
        if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
            message(FATAL_ERROR "hwloc library is required but has not been found")
Mathieu Faverge's avatar
Mathieu Faverge committed
805
        endif()
806 807
        if(CHAMELEON_SIMULATION AND (NOT SIMGRID_FOUND OR NOT SIMGRID_LIBRARIES))
            message(FATAL_ERROR "SimGrid library is required but has not been found")
Mathieu Faverge's avatar
Mathieu Faverge committed
808
        endif()
809 810 811 812 813 814 815 816 817
        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 )
Mathieu Faverge's avatar
Mathieu Faverge committed
818

819
endif( CHAMELEON_SCHED_STARPU )
Mathieu Faverge's avatar
Mathieu Faverge committed
820

821
if( CHAMELEON_SCHED_PARSEC )
Mathieu Faverge's avatar
Mathieu Faverge committed
822

823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
    # 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})

    # Add definition and include_dir if found
    if(PARSEC_FOUND)
        message("-- ${Blue}Add definition CHAMELEON_SCHED_PARSEC"
        " - Activate PaRSEC in Chameleon${ColourReset}")

843
      set(CHAMELEON_SCHED_PARSEC 1)
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
      include_directories(${PARSEC_INCLUDE_DIRS_DEP})
      include_directories(${PARSEC_INCLUDE_DIRS}/daguepp)
      set(CMAKE_REQUIRED_INCLUDES "${PARSEC_INCLUDE_DIRS_DEP}")

      if(PARSEC_LINKER_FLAGS)
           list(APPEND CMAKE_EXE_LINKER_FLAGS "${PARSEC_LINKER_FLAGS}")
      endif()
      foreach(libdir ${PARSEC_LIBRARY_DIRS_DEP})
          list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}")
      endforeach()
      string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
      set(CMAKE_REQUIRED_LIBRARIES "${PARSEC_LIBRARIES_DEP}")

      if(HWLOC_FOUND AND HWLOC_LIBRARY_DIRS)
            # the RPATH to be used when installing
          list(APPEND CMAKE_INSTALL_RPATH "${HWLOC_LIBRARY_DIRS}")
      endif()
      if(PARSEC_FOUND AND PARSEC_LIBRARY_DIRS_DEP)
          # the RPATH to be used when installing
          list(APPEND CMAKE_INSTALL_RPATH "${PARSEC_LIBRARY_DIRS_DEP}")
      endif()
      if (PARSEC_LIBRARIES)
          if (PARSEC_LIBRARIES_DEP)
              list(INSERT CHAMELEON_DEP 0 ${PARSEC_LIBRARIES_DEP})
          else()
              list(INSERT CHAMELEON_DEP 0 ${PARSEC_LIBRARIES})
870
          endif()
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
      endif()
    else ( PARSEC_FOUND )
        if(MORSE_VERBOSE_FIND_PACKAGE)
            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})
Mathieu Faverge's avatar
Mathieu Faverge committed
886
                    endif ()
887 888 889 890 891
                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})
Mathieu Faverge's avatar
Mathieu Faverge committed
892 893 894 895
                        endif ()
                    endforeach()
                endif()
            endif()
896 897 898 899 900 901 902 903 904 905 906
        else(MORSE_VERBOSE_FIND_PACKAGE)
            message(WARNING "PaRSEC library has not been found and MORSE_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate MORSE_VERBOSE_FIND_PACKAGE option (-DMORSE_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
        endif(MORSE_VERBOSE_FIND_PACKAGE)
        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 )
Mathieu Faverge's avatar
Mathieu Faverge committed
907

908
endif( CHAMELEON_SCHED_PARSEC )
Mathieu Faverge's avatar
Mathieu Faverge committed
909

910 911
      # try to find quark runtime
if( CHAMELEON_SCHED_QUARK )
912

913
    find_package(QUARK COMPONENTS HWLOC)
914

915 916 917 918
    # Add definition and include_dir if found
    if(QUARK_FOUND)
        message("-- ${Blue}Add definition CHAMELEON_SCHED_QUARK"
        " - Activate QUARK in Chameleon${ColourReset}")
919
        set(CHAMELEON_SCHED_QUARK 1)
920 921 922 923 924 925 926 927
        include_directories(${QUARK_INCLUDE_DIRS})
        if(QUARK_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${QUARK_LIBRARY_DIRS}")
        endif()
        if (QUARK_LIBRARIES)
            if (QUARK_LIBRARIES_DEP)
                list(INSERT CHAMELEON_DEP 0 ${QUARK_LIBRARIES_DEP})
928
            else()
929
                list(INSERT CHAMELEON_DEP 0 ${QUARK_LIBRARIES})
930
            endif()
931 932 933
        endif()
    else(QUARK_FOUND)
        if(MORSE_VERBOSE_FIND_PACKAGE)
934
            if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
935 936 937 938 939 940
                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 ()
941
            endif()
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
            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()
            message(WARNING "QUARK library has not been found and MORSE_VERBOSE_FIND_PACKAGE is set to OFF."
            " Try to activate MORSE_VERBOSE_FIND_PACKAGE option (-DMORSE_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
        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)
957

958
endif()
959

960 961 962 963 964 965
# 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)

966 967 968 969 970 971
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()
972

973
#------------------------------------------------------------------------------
974 975 976 977 978 979 980 981 982 983
if(CHAMELEON_SCHED_STARPU)
    link_directories(${STARPU_LIBRARY_DIRS_DEP})
elseif(CHAMELEON_SCHED_PARSEC)
    link_directories(${PARSEC_LIBRARY_DIRS_DEP})
elseif(CHAMELEON_SCHED_QUARK)
    link_directories(${QUARK_LIBRARY_DIRS})
endif()
if(NOT CHAMELEON_SIMULATION)
    if(CHAMELEON_USE_CUDA)
        link_directories(${CUDA_LIBRARY_DIRS})
984
    endif()
985 986
endif()

987 988 989
# Save extra dependencies (all required links)
list(APPEND CHAMELEON_DEP ${EXTRA_LIBRARIES})
list(REMOVE_DUPLICATES CHAMELEON_DEP) # WARNING: is it safe, respect order?
990

991 992
# Check for the subdirectories
# ----------------------------
993

994 995 996 997 998 999
# 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)
1000 1001


1002 1003 1004
###############################################################################
# Coreblas library (kernels for CPUs) #
#######################################
1005

1006 1007
add_subdirectory(coreblas)
#------------------------------------------------------------------------------
1008 1009


1010 1011 1012
###############################################################################
# Cudablas library (kernels for CUDAs) #
########################################
1013

1014 1015 1016 1017
if(CHAMELEON_USE_CUDA)
    add_subdirectory(cudablas)
endif()
#------------------------------------------------------------------------------
1018 1019


1020 1021 1022
###############################################################################
# Main library #
################
1023

1024 1025 1026 1027
add_subdirectory(include)
add_subdirectory(control)
add_subdirectory(compute)
#------------------------------------------------------------------------------
1028 1029


1030 1031 1032
###############################################################################
# Runtime library #
###################
1033

1034 1035
add_subdirectory(runtime)
#------------------------------------------------------------------------------
1036 1037


1038 1039 1040
###############################################################################
# Executables and Tests #
#########################
1041

1042 1043
enable_testing()
include(CTest)
1044

1045 1046 1047 1048 1049 1050 1051
# 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)
1052

1053
# Testing executables
1054
if(CHAMELEON_ENABLE_EXAMPLE AND NOT CHAMELEON_SIMULATION)
1055
  add_subdirectory(example)
1056
endif(CHAMELEON_ENABLE_EXAMPLE AND NOT CHAMELEON_SIMULATION)
1057

1058
# Testing executables
1059
if(CHAMELEON_ENABLE_TESTING AND NOT CHAMELEON_SIMULATION)
1060
  add_subdirectory(testing)
1061
endif(CHAMELEON_ENABLE_TESTING AND NOT CHAMELEON_SIMULATION)
1062

1063 1064 1065 1066 1067
# Timing executables
if(CHAMELEON_ENABLE_TIMING)
  add_subdirectory(timing)
endif(CHAMELEON_ENABLE_TIMING)
#------------------------------------------------------------------------------
1068 1069


1070 1071 1072
###############################################################################
# Documentation #
#################
1073

1074 1075 1076 1077
if(CHAMELEON_ENABLE_DOCS)
    add_subdirectory(docs)
    if (DOXYGEN_EXECUTABLE AND MAKEINFO_COMPILER AND TEXI2DVI_COMPILER AND TEX_COMPILER)
        add_custom_target(docs ALL DEPENDS doxygen-out doc-info-users_guide doc-html-users_guide doc-pdf-users_guide)
1078
    endif()
1079 1080
endif()
#------------------------------------------------------------------------------
1081

1082 1083 1084
###############################################################################
# Config files (pkg_config) #
#############################
1085

1086 1087
# Create .pc file 
# ---------------
PRUVOST Florent's avatar
PRUVOST Florent committed
1088
generate_pkgconfig_file()
1089 1090 1091 1092 1093 1094 1095
#------------------------------------------------------------------------------

###############################################################################
# Release source #
##################
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_PACKAGE_NAME "chameleon")
1096
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.org)
PRUVOST Florent's avatar
PRUVOST Florent committed
1097 1098 1099 1100
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}")
1101
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
PRUVOST Florent's avatar
PRUVOST Florent committed
1102 1103 1104
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")
1105
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.org)
PRUVOST Florent's avatar
PRUVOST Florent committed
1106 1107
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")
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
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()
1121

1122 1123 1124
###
### END CMakeLists.txt
###