CMakeLists.txt 34 KB
Newer Older
1 2 3 4 5 6
###
#
# @copyright (c) 2009-2014 The University of Tennessee and The University
#                          of Tennessee Research Foundation.
#                          All rights reserved.
# @copyright (c) 2012-2014 Inria. All rights reserved.
7
# @copyright (c) 2012-2014 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.0
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_PATCH 0)
43 44 45 46 47 48 49 50 51 52 53

# Add extra cmake module path and initialize morse cmake modules
# --------------------------------------------------------------
set( MORSE_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/morse )
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
list(APPEND CMAKE_MODULE_PATH ${MORSE_CMAKE_MODULE_PATH})
include(MorseInit)
include(GenPkgConfig)

#############################################
#                                           #
PRUVOST Florent's avatar
space  
PRUVOST Florent committed
54
#        Compilation of CHAMELEON           #
55 56 57 58 59 60 61 62
#                                           #
#############################################


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

63 64
set(CHAMELEON_DEFINITIONS_LIST "")

PRUVOST Florent's avatar
PRUVOST Florent committed
65 66 67 68 69 70 71 72
# 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)
73
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
PRUVOST Florent's avatar
PRUVOST Florent committed
74 75 76 77

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

78 79 80 81
# Misc options
# ------------
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

82
# Define precision supported by CHAMELEON
83
# -----------------------------------------
84 85
set( RP_CHAMELEON_DICTIONNARY ${MORSE_CMAKE_MODULE_PATH}/precision_generator/subs.py )
set( RP_CHAMELEON_PRECISIONS  "s;d;c;z" )
86 87 88 89 90 91
include(RulesPrecisions)

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

# Create a list of possible runtime
92
set(CHAMELEON_SCHED_list "STARPU" "QUARK")
93 94

# Initially StarPU runtime is enabled
95
option(CHAMELEON_SCHED_STARPU
96
    "Enable StarPU scheduler as the default runtime
97 98
    (Conflict with other CHAMELEON_SCHED_* options)" ON)
option(CHAMELEON_SCHED_QUARK
99
    "Enable Quark scheduler as the default runtime
100
    (Conflict with other CHAMELEON_SCHED_* options)" OFF)
101

102 103 104 105
if (CHAMELEON_SCHED_QUARK)
    set(CHAMELEON_SCHED_STARPU OFF)
elseif (CHAMELEON_SCHED_STARPU)
    set(CHAMELEON_SCHED_QUARK OFF)
106
endif()
107 108 109 110 111 112 113 114 115
if (CHAMELEON_SCHED_STARPU)
    message("-- ${BoldGreen}CHAMELEON_SCHED_STARPU is set to ON: CHAMELEON uses StarPU runtime${ColourReset}")
    message("-- ${BoldGreen}To use CHAMELEON with QUARK runtime: set CHAMELEON_SCHED_QUARK"
    "to ON (CHAMELEON_SCHED_STARPU will be disabled)${ColourReset}")
elseif(CHAMELEON_SCHED_QUARK)
    message("-- ${BoldGreen}CHAMELEON_SCHED_QUARK is set to ON: CHAMELEON uses QUARK runtime${ColourReset}")
    message("-- ${BoldGreen}To use CHAMELEON with StarPU runtime: set CHAMELEON_SCHED_STARPU"
    "to ON (CHAMELEON_SCHED_QUARK will be disabled)${ColourReset}")
endif()
116 117 118 119

# 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)
120 121
foreach (runtime ${CHAMELEON_SCHED_list})
    if (CHAMELEON_SCHED_${runtime})
122 123 124 125 126 127 128 129 130 131
        math(EXPR number_of_active_runtime "${number_of_active_runtime}+1")
    endif()
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()

# Warning if not coherent options
132 133
if (CHAMELEON_USE_MPI AND NOT CHAMELEON_SCHED_STARPU)
    message(WARNING "You have activated MPI but CHAMELEON_SCHED_STARPU is OFF.\n"
134
    "You should use StarPU Runtime system if you want to benefit from MPI.\n"
135
    "Use -DCHAMELEON_SCHED_QUARK=OFF -DCHAMELEON_SCHED_STARPU=ON at cmake \n"
136 137 138
    "configure to do so.")
endif()

139 140
if(CHAMELEON_USE_CUDA AND NOT CHAMELEON_SCHED_STARPU)
    message(WARNING "You have activated CUDA but CHAMELEON_SCHED_STARPU is OFF.\n"
141
    "You should use StarPU Runtime system if you want to benefit from GPUs.\n"
142
    "Use -DCHAMELEON_SCHED_QUARK=OFF -DCHAMELEON_SCHED_STARPU=ON at cmake \n"
143 144 145
    "configure to do so.")
endif()

146 147
if(CHAMELEON_USE_MAGMA AND NOT CHAMELEON_SCHED_STARPU)
    message(WARNING "You have activated MAGMA but CHAMELEON_SCHED_STARPU is OFF.\n"
148
    "You should use StarPU Runtime system if you want to benefit from GPUs.\n"
149
    "Use -DCHAMELEON_SCHED_QUARK=OFF -DCHAMELEON_SCHED_STARPU=ON at cmake \n"
150 151 152
    "configure to do so.")
endif()

153 154
if(CHAMELEON_USE_FXT AND NOT CHAMELEON_SCHED_STARPU)
    message(WARNING "You have activated FXT but CHAMELEON_SCHED_STARPU is OFF.\n"
155
    "You should use StarPU Runtime system if you want to benefit from FxT.\n"
156
    "Use -DCHAMELEON_SCHED_QUARK=OFF -DCHAMELEON_SCHED_STARPU=ON at cmake \n"
157 158
    "configure to do so.")
endif()
159

160 161 162 163 164
# Additional options
# ------------------

# Enable the distributed interface (allowed only when StarPU is enabled)
# TODO: Default should be changed to ON/OFF when it will be ok
165
cmake_dependent_option(CHAMELEON_USE_MPI
166
                    "Enable distributed memory through MPI" OFF
167
                    "CHAMELEON_SCHED_STARPU" OFF)
168
if (NOT CHAMELEON_USE_MPI)
169
    message("-- ${BoldGreen}CHAMELEON_USE_MPI is set to OFF, turn it ON to use MPI (only with StarPU)${ColourReset}")
170
endif()
171 172 173

# Enable Cuda kernels if StarPU (only if StarPU runtime is enabled)
# TODO: Default should be changed to ON/OFF when it will be ok
174
cmake_dependent_option(CHAMELEON_USE_CUDA
175
                    "Enable CUDA kernels" OFF
176
                    "CHAMELEON_SCHED_STARPU" OFF)
177
if (NOT CHAMELEON_USE_CUDA)
178
    message("-- ${BoldGreen}CHAMELEON_USE_CUDA is set to OFF, turn it ON to use CUDA (only with StarPU)${ColourReset}")
179
endif()
180 181

# Enable MAGMA advanced kernels if CUDA is enabled
182
cmake_dependent_option(CHAMELEON_USE_MAGMA
183
                    "Enable MAGMA Cuda kernels" OFF
184
                    "CHAMELEON_USE_CUDA" OFF)
185
if (NOT CHAMELEON_USE_MAGMA)
186
    message("-- ${BoldGreen}CHAMELEON_USE_MAGMA is set to OFF, turn it ON to use MAGMA (only with StarPU)${ColourReset}")
187
endif()
188 189

# Enable FXT if StarPU (only if StarPU runtime is enabled)
190
cmake_dependent_option(CHAMELEON_USE_FXT
191
                    "Enable FXT with STARPU" OFF
192
                    "CHAMELEON_SCHED_STARPU" OFF)
193
if (NOT CHAMELEON_USE_FXT)
194
    message("-- ${BoldGreen}CHAMELEON_USE_FXT is set to OFF, turn it ON to use FxT (only with StarPU)${ColourReset}")
195
endif()
196 197 198

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

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

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


###############################################################################
# Look for dependencies #
#########################

236 237 238 239
#find_package(MUMPS REQUIRED COMPONENTS SEQ)
#find_package(MUMPS REQUIRED)
#message(FATAL_ERROR "MUMPS_FOUND: ${MUMPS_FOUND}")

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
# Check for Thread library
# ------------------------
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
if( THREADS_FOUND )
    list(APPEND EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
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(
        M_m_LIBRARY
        NAMES m
        )
    mark_as_advanced(M_m_LIBRARY)
    if (M_m_LIBRARY)
        list(APPEND M_LIBRARIES "${M_m_LIBRARY}")
        list(APPEND EXTRA_LIBRARIES "${M_m_LIBRARY}")
    else()
        message(FATAL_ERROR "Could NOT find libm on your system."
262
            "Are you sure to a have a C compiler installed?")
263 264 265
    endif()
endif()

266
# Try to find librt (libposix4 - POSIX.1b Realtime Extensions library)
267 268 269 270 271 272 273 274 275 276 277 278
# 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()
279
        message(FATAL_ERROR "Could NOT find librt on your system")
280 281 282
    endif()
endif()

283
# If simulation we don't enter in kernel functions so that we don't need to
284
# link with concerned libraries
285
if(NOT CHAMELEON_SIMULATION)
286

287
    # CHAMELEON depends on CBLAS
288 289
    #----------------------------
    find_package(BLASEXT REQUIRED)
290 291 292
    if(BLAS_FOUND AND BLAS_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${BLAS_LIBRARY_DIRS}")
293 294
    else()
        message(FATAL_ERROR "A BLAS library is required but has not been found")
295
    endif()
296

297
    find_package(CBLAS)
298 299
    if(CBLAS_FOUND)
        include_directories(${CBLAS_INCLUDE_DIRS})
300 301 302 303 304
        if(CBLAS_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${CBLAS_LIBRARY_DIRS}")
        endif()
    else()
305
        if(MORSE_VERBOSE_FIND_PACKAGE)
306 307 308 309 310 311 312 313 314
            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 ()
            endif()
        else()
315 316
            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")
317 318
        endif()
        message(FATAL_ERROR "A CBLAS library is required but has not been found")
319
    endif()
320

321 322
    # CHAMELEON depends on LAPACKE
    #-----------------------------
323
    find_package(LAPACKEXT REQUIRED)
324 325 326
    if(LAPACK_FOUND AND LAPACK_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${LAPACK_LIBRARY_DIRS}")
327 328
    else()
        message(FATAL_ERROR "A LAPACK library is required but has not been found")
329
    endif()
330 331

    # standalone version of lapacke seems useless for now
332
    # let the comment in case we meet some problems of non existing lapacke
333
    # functions in lapack library such as mkl, acml, ...
334
    #set(LAPACKE_STANDALONE TRUE)
335
    find_package(LAPACKE)
336 337
    if(LAPACKE_FOUND)
        include_directories(${LAPACKE_INCLUDE_DIRS})
338 339 340 341 342
        if(LAPACKE_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${LAPACKE_LIBRARY_DIRS}")
        endif()
    else()
343
        if(MORSE_VERBOSE_FIND_PACKAGE)
344 345 346 347 348 349 350 351 352
            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 ()
            endif()
        else()
353 354
            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")
355 356
        endif()
        message(FATAL_ERROR "A LAPACKE library is required but has not been found")
357
    endif()
358

359
    # CHAMELEON depends on TMG
360
    #--------------------------
361
    if (CHAMELEON_ENABLE_TESTING OR CHAMELEON_ENABLE_TIMING)
362
        find_package(TMG)
363 364 365
        if(TMG_FOUND AND TMG_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${TMG_LIBRARY_DIRS}")
366 367
        else()
            message(FATAL_ERROR "A TMG library is required but has not been found")
368
        endif()
369 370
    endif()

371
    # CHAMELEON depends on CUDA/CUBLAS
372
    #----------------------------------
373
    if (CHAMELEON_USE_CUDA)
374 375 376 377

        find_package(CUDA REQUIRED)

        if (CUDA_FOUND)
378
            message("-- ${Blue}Add definition CHAMELEON_USE_CUDA"
379
            " - Activate CUDA in Chameleon${ColourReset}")
380
            add_definitions(-DCHAMELEON_USE_CUDA)
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
            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)
            include_directories(${CUDA_INCLUDE_DIRS})
            list(APPEND EXTRA_LIBRARIES ${CUDA_LIBRARIES}) # need CUDA libs to link.
            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)
            else()
                check_function_exists(cuDeviceCanAccessPeer CUDA_HAVE_PEER_DEVICE_MEMORY_ACCESS)
            endif()
            set(CMAKE_REQUIRED_INCLUDES  "${saved_include}")
            set(CMAKE_REQUIRED_LIBRARIES "${saved_libs}")
399 400
            #FindHeader(CUDA cublas_v2.h)
            #if(CUDA_cublas_v2.h_DIRS)
401
                #add_definitions(-DCHAMELEON_USE_CUBLAS_V2)
402
            #endif()
403 404
        endif (CUDA_FOUND)

405
        # CHAMELEON depends on MAGMA gpu kernels
406 407 408
        # call our cmake module to test (in cmake_modules)
        # change this call position if not appropriated
        #----------------------------------------------
409 410 411 412
        if ( CUDA_FOUND AND CHAMELEON_USE_MAGMA )
            set(CHAMELEON_MAGMA_VERSION "1.4" CACHE STRING "oldest MAGMA version desired")
            find_package(MAGMA ${CHAMELEON_MAGMA_VERSION} COMPONENTS CBLAS LAPACK CUDA)
            if ( MAGMA_FOUND )
413 414
                message("-- ${Blue}Add definition CHAMELEON_USE_CUBLAS"
                " - Use GPU kernels from cuBLAS${ColourReset}")
415
                add_definitions(-DCHAMELEON_USE_CUBLAS)
416 417
                message("-- ${Blue}Add definition CHAMELEON_USE_MAGMA"
                " - Use GPU kernels from MAGMA${ColourReset}")
418 419 420 421 422 423 424 425
                add_definitions(-DCHAMELEON_USE_MAGMA)
                list(APPEND EXTRA_LIBRARIES ${CUDA_CUBLAS_LIBRARIES})
                include_directories(${MAGMA_INCLUDE_DIRS})
                if(MAGMA_LIBRARY_DIRS)
                    # the RPATH to be used when installing
                    list(APPEND CMAKE_INSTALL_RPATH "${MAGMA_LIBRARY_DIRS}")
                endif()
            else( MAGMA_FOUND )
426
                if(MORSE_VERBOSE_FIND_PACKAGE)
427 428 429 430 431 432 433
                    if (NOT MAGMA_magma.h_DIRS)
                        Print_Find_Header_Status(magma magma.h)
                    endif ()
                    if (NOT MAGMA_magma_LIBRARY)
                        Print_Find_Library_Status(magma libmagma)
                    endif ()
                else()
434 435
                    message(WARNING "MAGMA 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")
436 437 438
                endif()
                message(FATAL_ERROR "MAGMA library is required but has not been found")
            endif( MAGMA_FOUND )
439 440
        endif()

441
    endif(CHAMELEON_USE_CUDA)
442

443
    # CHAMELEON depends on MPI
444
    #-------------------------
445
    if (CHAMELEON_USE_MPI)
446 447 448

        # allows to use an external mpi compilation by setting compilers with
        # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
449
        # at cmake configure
450 451 452 453 454 455
        if(NOT MPI_C_COMPILER)
            set(MPI_C_COMPILER mpicc)
        endif()
        find_package(MPI REQUIRED)

        if (MPI_C_FOUND)
456 457
            message("-- ${Blue}Add definition CHAMELEON_USE_MPI"
            " - Activate MPI in Chameleon${ColourReset}")
458
            add_definitions(-DCHAMELEON_USE_MPI)
459 460 461 462 463 464 465
            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")
        endif (MPI_C_FOUND)

466
    endif (CHAMELEON_USE_MPI)
467

468
else (NOT CHAMELEON_SIMULATION)
469

470
    message("${BoldBlue}Simulation mode of CHAMELEON is activated (CHAMELEON_SIMULATION=ON)."
471
        "\nThis mode allows you to simulate execution of algorithms with StarPU compiled with SimGrid."
472
        "\nTo do so, we provide some perfmodels in the simucore/perfmodels/ directory of CHAMELEON sources."
473 474 475 476 477 478 479
        "\nThe resulting directory where to find perfmodels is: ${CMAKE_CURRENT_SOURCE_DIR}/simucore/perfmodels."
        "\nTo use these perfmodels, please set your STARPU_HOME environment variable to ${CMAKE_CURRENT_SOURCE_DIR}/simucore/perfmodels."
        "\nFinally, you need to set your STARPU_HOSTNAME environment variable to the name of the machine to simulate."
        "For example: STARPU_HOSTNAME=mirage."
        "\nNote that only POTRF kernels with block sizes of 320 or 960 (simple and double precision) on mirage machine are available for now."
        "\nDatabase of models is subject to change, it should be enrich in a near future.${ColourReset}")

480 481 482 483
    if (CHAMELEON_USE_CUDA)
        set(CHAMELEON_USE_CUDA OFF)
        message("${BoldBlue}CHAMELEON_USE_CUDA is set to ON but we turn it OFF."
        "Because we are compiling the simulation mode (CHAMELEON_SIMULATION=ON),"
484 485
        "we do not need to link with CUDA.${ColourReset}")
    endif ()
486 487 488 489
    if (CHAMELEON_USE_MAGMA)
        set(CHAMELEON_USE_MAGMA OFF)
        message("${BoldBlue}CHAMELEON_USE_MAGMA is set to ON but we turn it OFF."
        "Because we are compiling the simulation mode (CHAMELEON_SIMULATION=ON),"
490 491
        "we do not need to link with MAGMA.${ColourReset}")
    endif ()
492 493 494 495
    if (CHAMELEON_USE_MPI)
        set(CHAMELEON_USE_MPI OFF)
        message("${BoldBlue}CHAMELEON_USE_MPI is set to ON but we turn it OFF."
        "Because we are compiling the simulation mode (CHAMELEON_SIMULATION=ON),"
496 497
        "we do not need to link with MPI.${ColourReset}")
    endif ()
498 499 500 501
    if (CHAMELEON_ENABLE_TESTING)
        set(CHAMELEON_ENABLE_TESTING OFF)
        message("${BoldBlue}CHAMELEON_ENABLE_TESTING is set to ON but we turn it OFF."
        "Because we are compiling the simulation mode (CHAMELEON_SIMULATION=ON),"
502 503 504 505
        "there is no sense in compiling testing drivers that are used to check"
        "numerical correctness of algorithms and kernels.${ColourReset}")
    endif ()

506
endif(NOT CHAMELEON_SIMULATION)
507 508


509
# CHAMELEON depends on a runtime
510 511 512 513
# -------------------------------

# TODO: discuss on this with Manu
# try to find starpu runtime
514
if( CHAMELEON_SCHED_STARPU )
515

516
    set(CHAMELEON_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
517 518

    # create list of components in order to make a single call to find_package(starpu...)
519
    if(NOT CHAMELEON_SIMULATION)
520
        set(STARPU_COMPONENT_LIST "HWLOC")
521
        if(CHAMELEON_USE_MPI)
522 523
            list(APPEND STARPU_COMPONENT_LIST "MPI")
        endif()
524
        if(CHAMELEON_USE_CUDA)
525 526 527
            list(APPEND STARPU_COMPONENT_LIST "CUDA")
        endif()
    endif()
528
    if(CHAMELEON_USE_FXT)
529 530 531
        list(APPEND STARPU_COMPONENT_LIST "FXT")
    endif()

532
    find_package(STARPU ${CHAMELEON_STARPU_VERSION}
533 534 535
                 COMPONENTS ${STARPU_COMPONENT_LIST})

    # Add definition and include_dir if found
536
    if ( STARPU_FOUND )
537
        message("-- ${Blue}Add definition CHAMELEON_SCHED_STARPU"
538
        " - Activate StarPU in Chameleon${ColourReset}")
539
        add_definitions(-DCHAMELEON_SCHED_STARPU) # TODO: remove that
540 541 542 543 544 545
        include_directories(${STARPU_INCLUDE_DIRS})
        set(CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS}")
        foreach(libdir ${STARPU_LIBRARY_DIRS})
            list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}")
        endforeach()
        string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
546 547
        if(CHAMELEON_USE_FXT)
            # check if fxt profiling is accessible in starpu and activate it in chameleon
548 549 550 551
            set(CMAKE_REQUIRED_LIBRARIES "${STARPU_SHM_LIBRARIES}")
            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 )
552 553
                message("-- ${Blue}Add definition HAVE_STARPU_FXT_PROFILING"
                " - Activate FxT profiling through StarPU${ColourReset}")
554
                add_definitions(-DHAVE_STARPU_FXT_PROFILING)
555
            else()
556 557 558
                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}")
559 560
            endif()
        endif()
561
        if (CHAMELEON_USE_MPI AND STARPU_MPI_LIBRARIES)
562 563 564
            # Check if a specific function exist
            set(CMAKE_REQUIRED_LIBRARIES "${STARPU_MPI_LIBRARIES}")
            unset(STARPU_MPI_DATA_REGISTER_FOUND CACHE)
565
            check_function_exists(starpu_mpi_data_register_comm STARPU_MPI_DATA_REGISTER_FOUND)
566
            if ( STARPU_MPI_DATA_REGISTER_FOUND )
567 568
                message("-- ${Blue}Add definition HAVE_STARPU_MPI_DATA_REGISTER - Activate"
                "use of starpu_mpi_data_register() in Chameleon with StarPU${ColourReset}")
569
                add_definitions(-DHAVE_STARPU_MPI_DATA_REGISTER)
570 571 572 573
            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}")
574 575
            endif()
        endif()
576 577 578 579 580 581 582 583 584 585 586 587
        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(STARPU_FOUND AND STARPU_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${STARPU_LIBRARY_DIRS}")
        endif()
588
    else ( STARPU_FOUND )
589
        if(MORSE_VERBOSE_FIND_PACKAGE)
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
            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(CHAMELEON_USE_FXT 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)
                endif ()
            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) )
              )
                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()
622 623 624 625
        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)
626 627 628 629 630 631 632 633 634 635 636 637
        if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
            message(FATAL_ERROR "hwloc library is required but has not been found")
        endif()
        if(CHAMELEON_USE_FXT 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 )
638

639
endif( CHAMELEON_SCHED_STARPU )
640 641

# try to find quark runtime
642
if( CHAMELEON_SCHED_QUARK )
643

644
    find_package(QUARK COMPONENTS HWLOC)
645 646 647

    # Add definition and include_dir if found
    if(QUARK_FOUND)
648
        message("-- ${Blue}Add definition CHAMELEON_SCHED_QUARK"
649
        " - Activate QUARK in Chameleon${ColourReset}")
650
        add_definitions(-DCHAMELEON_SCHED_QUARK) # TODO: remove that
651
        include_directories(${QUARK_INCLUDE_DIRS})
652 653 654 655 656
        if(QUARK_LIBRARY_DIRS)
            # the RPATH to be used when installing
            list(APPEND CMAKE_INSTALL_RPATH "${QUARK_LIBRARY_DIRS}")
        endif()
    else(QUARK_FOUND)
657
        if(MORSE_VERBOSE_FIND_PACKAGE)
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
            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 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()
673 674
            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")
675 676 677 678 679 680
        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)
681 682 683

endif()

684 685 686 687 688 689
# Add define for Fortran Mangling (should be defined somewhere else)
# ------------------------------------------------------------------
message("-- ${Blue}Add definition ADD_"
        " - For Fortran mangling${ColourReset}")
add_definitions(-DADD_)

690
#------------------------------------------------------------------------------
691
# Save all dependencies (all required links)
692 693 694 695 696
set(CHAMELEON_DEP -lchameleon)
if(CHAMELEON_SCHED_STARPU)
    if ( CHAMELEON_USE_MPI )
        list(APPEND CHAMELEON_DEP
          -lchameleon_starpu
697 698 699
          ${STARPU_MPI_LIBRARIES}
        )
    else()
700 701
        list(APPEND CHAMELEON_DEP
          -lchameleon_starpu
702 703 704
          ${STARPU_SHM_LIBRARIES}
        )
    endif()
705 706 707
elseif(CHAMELEON_SCHED_QUARK)
    list(APPEND CHAMELEON_DEP
      -lchameleon_quark
708 709 710 711
      ${QUARK_LIBRARIES}
      )
    link_directories(${QUARK_LIBRARY_DIRS})
endif()
712 713 714
if(NOT CHAMELEON_SIMULATION)
    if(CHAMELEON_USE_CUDA)
        list(APPEND CHAMELEON_DEP
715 716 717 718
        ${CUDA_LIBRARIES}
        )
        link_directories(${CUDA_LIBRARY_DIRS})
    endif()
719 720
    if(CHAMELEON_USE_MAGMA)
        list(APPEND CHAMELEON_DEP
721 722 723 724 725
        ${MAGMA_LIBRARIES}
        )
        link_directories(${MAGMA_LIBRARY_DIRS})
    endif()

726
    list(APPEND CHAMELEON_DEP
727 728
    -lcoreblas
    ${LAPACKE_LIBRARIES}
729
    ${CBLAS_LIBRARIES}
730 731 732 733 734 735
    ${LAPACK_SEQ_LIBRARIES}
    ${BLAS_SEQ_LIBRARIES}
    ${HWLOC_LIBRARIES}
    ${EXTRA_LIBRARIES}
    )
else()
736
    list(APPEND CHAMELEON_DEP
737
    -lcoreblas
738
    -lsimulapacke
739 740 741 742 743
    -lsimucblas
    ${HWLOC_LIBRARIES}
    ${EXTRA_LIBRARIES}
    )
endif()
744
list(REMOVE_DUPLICATES CHAMELEON_DEP)
745 746 747 748 749 750

# Check for the subdirectories
# ----------------------------

# include headers
# ---------------
751 752
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
753 754 755 756 757 758 759
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)

###############################################################################
# simucore libraries #
######################

760
if ( CHAMELEON_SIMULATION )
761
    add_subdirectory(simucore)
762
    message("-- ${Blue}Add definition CHAMELEON_SIMULATION"
763
    " - Activate simulation mode in Chameleon (to use with StarPU+SimGrid)${ColourReset}")
764
    add_definitions(-DCHAMELEON_SIMULATION)
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
endif()
#------------------------------------------------------------------------------


###############################################################################
# Coreblas library (kernels for CPUs) #
#######################################

add_subdirectory(coreblas)
#------------------------------------------------------------------------------


###############################################################################
# Main library #
################

add_subdirectory(include)
add_subdirectory(control)
add_subdirectory(compute)
#------------------------------------------------------------------------------


###############################################################################
# Runtime library #
###################

add_subdirectory(runtime)
#------------------------------------------------------------------------------


###############################################################################
# Executables and Tests #
#########################

enable_testing()
include(CTest)
#enable_testing()

# 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")
    set(CMAKE_Fortran_FLAGS "-nofor_main")
endif(_match_ifort)

# Testing executables
812
if(CHAMELEON_ENABLE_EXAMPLE)
813
  add_subdirectory(example)
814
endif(CHAMELEON_ENABLE_EXAMPLE)
815 816

# Testing executables
817
if(CHAMELEON_ENABLE_TESTING)
818
  add_subdirectory(testing)
819
endif(CHAMELEON_ENABLE_TESTING)
820 821

# Timing executables
822
if(CHAMELEON_ENABLE_TIMING)
823
  add_subdirectory(timing)
824
endif(CHAMELEON_ENABLE_TIMING)
825 826 827 828 829 830 831
#------------------------------------------------------------------------------


###############################################################################
# Documentation #
#################

832
if(CHAMELEON_ENABLE_DOCS)
833 834 835 836 837 838 839 840 841 842 843
    add_subdirectory(docs)
endif()
#------------------------------------------------------------------------------


###############################################################################
# Config files (pkg_config) #
#############################

# Create file morse_starpu.pc
# ---------------------------
844 845
if(CHAMELEON_SCHED_STARPU)
    generate_pkgconfig_file("${CMAKE_CURRENT_SOURCE_DIR}/lib/pkgconfig/chameleon-starpu.pc.in")
846 847 848 849
endif()

# # Create file morse_quark.pc
# # --------------------------
850 851
if(CHAMELEON_SCHED_QUARK)
    generate_pkgconfig_file("${CMAKE_CURRENT_SOURCE_DIR}/lib/pkgconfig/chameleon-quark.pc.in")
852 853 854 855 856 857 858
endif()
#------------------------------------------------------------------------------


###############################################################################
# Print Options #
#################
859
get_directory_property( CHAMELEON_DEFINITIONS_LIST DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
860 861
include(PrintOpts)

862
if (${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local" OR ${CMAKE_INSTALL_PREFIX} STREQUAL "C:/Program Files")
863 864
    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}")
865 866
endif()

867 868 869
###
### END CMakeLists.txt
###