diff --git a/cmake/Modules/FindMETIS.cmake b/cmake/Modules/FindMETIS.cmake new file mode 100644 index 000000000..267cf264d --- /dev/null +++ b/cmake/Modules/FindMETIS.cmake @@ -0,0 +1,37 @@ +find_path(METIS_INCLUDE_DIR metis.h + PATHS "${METIS_DIR}" + ENV METIS_DIR + PATH_SUFFIXES include + ) + +find_library(METIS_LIBRARY NAMES metis + PATHS "${METIS_DIR}" + ENV METIS_DIR + PATH_SUFFIXES lib + ) + +mark_as_advanced(METIS_LIBRARY METIS_INCLUDE_DIR) + +#=============================================================================== +include(FindPackageHandleStandardArgs) +if(CMAKE_VERSION VERSION_GREATER 2.8.12) + if(METIS_INCLUDE_DIR) + file(STRINGS ${METIS_INCLUDE_DIR}/metis.h _versions + REGEX "^#define\ +METIS_VER_(MAJOR|MINOR|SUBMINOR) .*") + foreach(_ver ${_versions}) + string(REGEX MATCH "METIS_VER_(MAJOR|MINOR|SUBMINOR) *([0-9.]+)" _tmp "${_ver}") + set(_metis_${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) + endforeach() + set(METIS_VERSION "${_metis_MAJOR}.${_metis_MINOR}" CACHE INTERNAL "") + endif() + + find_package_handle_standard_args(METIS + REQUIRED_VARS + METIS_LIBRARY + METIS_INCLUDE_DIR + VERSION_VAR + METIS_VERSION) +else() + find_package_handle_standard_args(METIS DEFAULT_MSG + METIS_LIBRARY METIS_INCLUDE_DIR) +endif() diff --git a/cmake/Modules/FindMumps.cmake b/cmake/Modules/FindMumps.cmake index e5aa0fecc..fe885dd1f 100644 --- a/cmake/Modules/FindMumps.cmake +++ b/cmake/Modules/FindMumps.cmake @@ -1,187 +1,240 @@ #=============================================================================== # @file FindMumps.cmake # # @author Nicolas Richart # # @date creation: Fri Oct 24 2014 # @date last modification: Wed Jan 13 2016 # # @brief The find_package file for the Mumps solver # # @section LICENSE # # Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory # (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== -set(_MUMPS_COMPONENTS "sequential" "parallel") +set(_MUMPS_COMPONENTS "sequential" "parallel" "double" "float" "complex_double" "complex_float") if(NOT Mumps_FIND_COMPONENTS) - set(Mumps_FIND_COMPONENTS "parallel") + set(Mumps_FIND_COMPONENTS "parallel" "double" "float" "complex_double" "complex_float") endif() #=============================================================================== enable_language(Fortran) -if("${Mumps_FIND_COMPONENTS}" STREQUAL "sequential") - set(MUMPS_PREFIX _seq) -else() - unset(MUMPS_PREFIX) +set(MUMPS_PRECISIONS) +foreach(_comp ${Mumps_FIND_COMPONENTS}) + if("${_comp}" STREQUAL "sequential") + set(MUMPS_PLAT _seq) #default plat on debian based distribution + endif() + + if("${_comp}" STREQUAL "float") + list(APPEND MUMPS_PRECISIONS s) + endif() + if("${_comp}" STREQUAL "double") + list(APPEND MUMPS_PRECISIONS d) + endif() + if("${_comp}" STREQUAL "complex_float") + list(APPEND MUMPS_PRECISIONS c) + endif() + if("${_comp}" STREQUAL "complex_double") + list(APPEND MUMPS_PRECISIONS z) + endif() +endforeach() + +if(NOT MUMPS_PRECISIONS) + set(MUMPS_PRECISIONS s d c z) endif() -find_path(MUMPS_INCLUDE_DIR dmumps_c.h - HINTS ${MUMPS_DIR} - PATH_SUFFIXES include - ) +list(GET MUMPS_PRECISIONS 0 _first_precision) + +string(TOUPPER "${_first_precision}" _u_first_precision) + +set(_mumps_test_dir "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}") +file(WRITE "${_mumps_test_dir}/mumps_test_code.c" " +#include <${_first_precision}mumps_c.h> -find_library(MUMPS_LIBRARY_COMMON NAMES mumps_common${MUMPS_PREFIX} - HINTS ${MUMPS_DIR} - PATH_SUFFIXES lib - ) +int main() { + ${_u_first_precision}MUMPS_STRUC_C mumps_data; + ${_first_precision}mumps_c(&mumps_data); + return 0; +} +") -find_library(MUMPS_LIBRARY_PORD NAMES pord${MUMPS_PREFIX} - HINTS ${MUMPS_DIR} - PATH_SUFFIXES lib - ) -foreach(_precision s d c z) +find_path(MUMPS_INCLUDE_DIR ${_first_precision}mumps_c.h + PATHS "${MUMPS_DIR}" + ENV MUMPS_DIR + PATH_SUFFIXES include + ) + +set(_mumps_required_vars) +foreach(_precision ${MUMPS_PRECISIONS}) string(TOUPPER "${_precision}" _u_precision) find_library(MUMPS_LIBRARY_${_u_precision}MUMPS NAMES ${_precision}mumps${MUMPS_PREFIX} - HINTS ${MUMPS_DIR} /usr + PATHS "${MUMPS_DIR}" + ENV MUMPS_DIR PATH_SUFFIXES lib ) mark_as_advanced(MUMPS_LIBRARY_${_u_precision}MUMPS) + list(APPEND _mumps_required_vars MUMPS_LIBRARY_${_u_precision}MUMPS) endforeach() -mark_as_advanced( - MUMPS_LIBRARY_COMMON - MUMPS_LIBRARY_PORD - MUMPS_INCLUDE_DIR) - -#=============================================================================== -if(NOT MUMPS_FOUND) - set(MUMPS_DIR "" CACHE PATH "Prefix of MUMPS library.") - mark_as_advanced(MUMPS_DIR) -endif() #=============================================================================== include(FindPackageHandleStandardArgs) if(CMAKE_VERSION VERSION_GREATER 2.8.12) if(MUMPS_INCLUDE_DIR) file(STRINGS ${MUMPS_INCLUDE_DIR}/dmumps_c.h _versions REGEX "^#define MUMPS_VERSION .*") foreach(_ver ${_versions}) string(REGEX MATCH "MUMPS_VERSION *\"([0-9.]+)\"" _tmp "${_ver}") set(_mumps_VERSION ${CMAKE_MATCH_1}) endforeach() set(MUMPS_VERSION "${_mumps_VERSION}" CACHE INTERNAL "") endif() find_package_handle_standard_args(Mumps REQUIRED_VARS - MUMPS_LIBRARY_DMUMPS - MUMPS_LIBRARY_COMMON - MUMPS_LIBRARY_PORD + ${_mumps_required_vars} MUMPS_INCLUDE_DIR VERSION_VAR MUMPS_VERSION) else() find_package_handle_standard_args(Mumps DEFAULT_MSG - MUMPS_LIBRARIES MUMPS_INCLUDE_DIR) + ${_mumps_required_vars} MUMPS_INCLUDE_DIR) endif() +#=============================================================================== - -if (MUMPS_FOUND AND NOT TARGET MUMPS::common) - set(MUMPS_LIBRARIES_ALL ${MUMPS_LIBRARY_DMUMPS}) - - include(CheckFortranFunctionExists) - set(CMAKE_REQUIRED_LIBRARIES ${MUMPS_LIBRARIES_ALL}) - check_fortran_function_exists("blacs_gridinit" MUMPS_DOES_NOT_NEED_SCALAPACK) - set(CMAKE_REQUIRED_LIBRARIES) - - if(NOT MUMPS_DOES_NOT_NEED_SCALAPACK OR MUMPS_LIBRARY_COMMON MATCHES ".*mumps_common.*${CMAKE_STATIC_LIBRARY_SUFFIX}") +list(APPEND MUMPS_LIBRARIES_ALL ${MUMPS_LIBRARY_${_u_first_precision}MUMPS}) + +set(_mumps_dep_symbol_BLAS ${_first_precision}gemm) +set(_mumps_dep_symbol_ScaLAPACK numroc) +set(_mumps_dep_symbol_MPI mpi_send) +set(_mumps_dep_symbol_Scotch scotchfstratinit) +set(_mumps_dep_symbol_Scotch_ptscotch scotchfdgraphexit) +set(_mumps_dep_symbol_Scotch_esmumps esmumps) +set(_mumps_dep_symbol_mumps_common mumps_abort) +set(_mumps_dep_symbol_pord SPACE_ordering) +set(_mumps_dep_symbol_METIS metis_nodend) +set(_mumps_dep_symbol_ParMETIS ParMETIS_V3_NodeND) + +set(_mumps_dep_link_BLAS BLAS_LIBRARIES) +set(_mumps_dep_link_ScaLAPACK SCALAPACK_LIBRARIES) +set(_mumps_dep_link_MPI MPI_Fortran_LIBRARIES) +set(_mumps_dep_link_Scotch SCOTCH_LIBRARIES) +set(_mumps_dep_link_Scotch_ptscotch SCOTCH_LIBRARY_PTSCOTCH) +set(_mumps_dep_link_Scotch_esmumps SCOTCH_LIBRARY_ESMUMPS) +set(_mumps_dep_link_mumps_common MUMPS_LIBRARY_COMMON) +set(_mumps_dep_link_pord MUMPS_LIBRARY_PORD) +set(_mumps_dep_link_METIS METIS_LIBRARY) +set(_mumps_dep_link_ParMETIS PARMETIS_LIBRARY) + +set(_mumps_dep_comp_Scotch_ptscotch COMPONENTS ptscotch) +set(_mumps_dep_comp_Scotch_ptscotch COMPONENTS esmumps) + +set(_mumps_potential_dependencies mumps_common pord BLAS ScaLAPACK MPI + Scotch Scotch_ptscotch Scotch_esmumps METIS ParMETIS) + +if(MUMPS_LIBRARIES_ALL) + if(MUMPS_LIBRARY_${_u_first_precision}MUMPS MATCHES ".*${_first_precision}mumps.*${CMAKE_STATIC_LIBRARY_SUFFIX}") # Assuming mumps was compiled as a static library set(MUMPS_LIBRARY_TYPE STATIC CACHE INTERNAL "" FORCE) - set(_extra_dep_list pthread) - find_package(BLAS REQUIRED) - list(APPEND _extra_dep_list ${BLAS_LIBRARIES}) - if (CMAKE_Fortran_COMPILER MATCHES ".*gfortran") set(_compiler_specific gfortran) elseif (CMAKE_Fortran_COMPILER MATCHES ".*ifort") set(_compiler_specific ifcore) endif() - list(APPEND _extra_dep_list ${_compiler_specific}) - - list(APPEND MUMPS_LIBRARIES_ALL - ${MUMPS_LIBRARY_COMMON} - ${MUMPS_LIBRARY_PORD} - pthread - ${_compiler_specific} - ) - - if("${Mumps_FIND_COMPONENTS}" STREQUAL "parallel") - find_package(MPI REQUIRED) - list(APPEND _extra_dep_list ${MPI_Fortran_LIBRARIES}) - - find_package(ScaLAPACK REQUIRED) - list(APPEND _extra_dep_list ScaLAPACK) - - list(APPEND MUMPS_LIBRARIES_ALL - ${MPI_Fortran_LIBRARIES} - ${SCALAPACK_LIBRARIES} - ) - endif() + endif() - list(APPEND MUMPS_LIBRARIES_ALL - ${BLAS_LIBRARIES}) + try_compile(_mumps_compiles "${_mumps_test_dir}" SOURCES "${_mumps_test_dir}/mumps_test_code.c" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MUMPS_INCLUDE_DIR}" + LINK_LIBRARIES ${MUMPS_LIBRARIES_ALL} ${_compiler_specific} + OUTPUT_VARIABLE _out) - if(_extra_dep_list) - set(_extra_dep ";${_extra_dep_list}") - else() - set(_extra_dep) + foreach(_pdep ${_mumps_potential_dependencies}) + if(_mumps_compiles) + break() endif() - else() - set(MUMPS_LIBRARY_TYPE SHARED CACHE INTERNAL "" FORCE) - endif() - add_library(MUMPS::common ${MUMPS_LIBRARY_TYPE} IMPORTED GLOBAL) - add_library(MUMPS::pord ${MUMPS_LIBRARY_TYPE} IMPORTED GLOBAL) + if(_out MATCHES "${_mumps_dep_symbol_${_pdep}}") + if(_pdep STREQUAL "mumps_common") + find_library(MUMPS_LIBRARY_COMMON mumps_common${MUMPS_PREFIX} + PATHS "${MUMPS_DIR}" + ENV MUMPS_DIR + PATH_SUFFIXES lib + ) + + if(NOT TARGET MUMPS::common) + add_library(MUMPS::common ${MUMPS_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(MUMPS::common PROPERTIES + IMPORTED_LOCATION "${MUMPS_LIBRARY_COMMON}" + INTERFACE_INCLUDE_DIRECTORIES "${MUMPS_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C;Fortran") + list(APPEND _mumps_interface_link MUMPS::common) + elseif(_pdep STREQUAL "pord") + find_library(MUMPS_LIBRARY_PORD pord${MUMPS_PREFIX} + PATHS "${MUMPS_DIR}" + ENV MUMPS_DIR + PATH_SUFFIXES lib + ) + if(NOT TARGET MUMPS::pord) + add_library(MUMPS::pord ${MUMPS_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + #TODO adapt it for windows and dlls (check FindGSL as an example) + set_target_properties(MUMPS::pord PROPERTIES + IMPORTED_LOCATION "${MUMPS_LIBRARY_PORD}" + INTERFACE_INCLUDE_DIRECTORIES "${MUMPS_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C") + list(APPEND _mumps_interface_link MUMPS::pord) + elseif(_pdep MATCHES "Scotch") + find_package(Scotch REQUIRED ${_mumps_dep_comp_${_pdep}}) + list(APPEND _mumps_interface_link ${${_mumps_dep_link_${_pdep}}}) + else() + find_package(${_pdep} REQUIRED) + list(APPEND _mumps_interface_link ${${_mumps_dep_link_${_pdep}}}) + endif() + + list(APPEND MUMPS_LIBRARIES_ALL ${${_mumps_dep_link_${_pdep}}}) + + try_compile(_mumps_compiles "${_mumps_test_dir}" SOURCES "${_mumps_test_dir}/mumps_test_code.c" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MUMPS_INCLUDE_DIR}" + LINK_LIBRARIES ${MUMPS_LIBRARIES_ALL} ${_compiler_specific} + OUTPUT_VARIABLE _out) + + endif() + endforeach() +endif() - #TODO adapt it for windows and dlls (check FindGSL as an example) - set_target_properties(MUMPS::pord PROPERTIES - IMPORTED_LOCATION "${MUMPS_LIBRARY_PORD}" - INTERFACE_INCLUDE_DIRECTORIES "${MUMPS_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C") - set_target_properties(MUMPS::common PROPERTIES - IMPORTED_LOCATION "${MUMPS_LIBRARY_COMMON}" +set(MUMPS_LIBRARIES_ALL) +foreach(_precision ${MUMPS_PRECISIONS}) + string(TOUPPER "${_precision}" _u_precision) + set(_target MUMPS::${_precision}mumps) + if(NOT TARGET ${_target}) + add_library(${_target} ${MUMPS_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(${_target} PROPERTIES + IMPORTED_LOCATION "${MUMPS_LIBRARY_${_u_precision}MUMPS}" INTERFACE_INCLUDE_DIRECTORIES "${MUMPS_INCLUDE_DIR}" IMPORTED_LINK_INTERFACE_LANGUAGES "C;Fortran" - INTERFACE_LINK_LIBRARIES "MUMPS::pord${_extra_dep}") + INTERFACE_LINK_LIBRARIES "${_mumps_interface_link}") - foreach(_precision s d c z) - string(TOUPPER "${_precision}" _u_precision) - set(_target MUMPS::${_precision}mumps) - add_library(${_target} ${MUMPS_LIBRARY_TYPE} IMPORTED GLOBAL) - set_target_properties(${_target} PROPERTIES - IMPORTED_LOCATION "${MUMPS_LIBRARY_${_u_precision}MUMPS}" - INTERFACE_INCLUDE_DIRECTORIES "${MUMPS_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C;Fortran" - INTERFACE_LINK_LIBRARIES "MUMPS::common") - endforeach() + list(APPEND MUMPS_LIBRARIES_ALL ${_target}) +endforeach() - set(MUMPS_LIBRARIES ${MUMPS_LIBRARIES_ALL} CACHE INTERNAL "Libraries for MUMPS" FORCE) -endif() +set(MUMPS_LIBRARIES ${MUMPS_LIBRARIES_ALL} CACHE INTERNAL "" FORCE) diff --git a/cmake/Modules/FindParMETIS.cmake b/cmake/Modules/FindParMETIS.cmake new file mode 100644 index 000000000..a105cc9af --- /dev/null +++ b/cmake/Modules/FindParMETIS.cmake @@ -0,0 +1,37 @@ +find_path(PARMETIS_INCLUDE_DIR parmetis.h + PATHS "${PARMETIS_DIR}" + ENV PARMETIS_DIR + PATH_SUFFIXES include + ) + +find_library(PARMETIS_LIBRARY NAMES parmetis + PATHS "${PARMETIS_DIR}" + ENV PARMETIS_DIR + PATH_SUFFIXES lib + ) + +mark_as_advanced(PARMETIS_LIBRARY PARMETIS_INCLUDE_DIR) + +#=============================================================================== +include(FindPackageHandleStandardArgs) +if(CMAKE_VERSION VERSION_GREATER 2.8.12) + if(PARMETIS_INCLUDE_DIR) + file(STRINGS ${PARMETIS_INCLUDE_DIR}/parmetis.h _versions + REGEX "^#define\ +PARMETIS_(MAJOR|MINOR|SUBMINOR)_VERSION .*") + foreach(_ver ${_versions}) + string(REGEX MATCH "PARMETIS_(MAJOR|MINOR|SUBMINOR)_VERSION *([0-9.]+)" _tmp "${_ver}") + set(_parmetis_${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) + endforeach() + set(PARMETIS_VERSION "${_parmetis_MAJOR}.${_parmetis_MINOR}" CACHE INTERNAL "") + endif() + + find_package_handle_standard_args(ParMETIS + REQUIRED_VARS + PARMETIS_LIBRARY + PARMETIS_INCLUDE_DIR + VERSION_VAR + PARMETIS_VERSION) +else() + find_package_handle_standard_args(ParMETIS DEFAULT_MSG + PARMETIS_LIBRARY PARMETIS_INCLUDE_DIR) +endif() diff --git a/cmake/Modules/FindScaLAPACK.cmake b/cmake/Modules/FindScaLAPACK.cmake index fd51dd0a9..b0ffabc36 100644 --- a/cmake/Modules/FindScaLAPACK.cmake +++ b/cmake/Modules/FindScaLAPACK.cmake @@ -1,123 +1,117 @@ #=============================================================================== # @file FindScaLAPACK.cmake # # @author Nicolas Richart # # @date creation: Tue Mar 31 2015 # @date last modification: Wed Jan 13 2016 # # @brief The find_package file for the Mumps solver # # @section LICENSE # # Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory # (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== find_library(SCALAPACK_LIBRARY NAME scalapack - HINTS ${SCALAPACK_DIR} PATH_SUFFIXES lib) + PATHS "${SCALAPACK_DIR}" ENV SCALAPACK_DIR PATH_SUFFIXES lib) mark_as_advanced(SCALAPACK_LIBRARY) -#=============================================================================== -if(NOT SCALAPACK_FOUND) - set(SCALAPACK_DIR "" CACHE PATH "Prefix of MUMPS library.") - mark_as_advanced(SCALAPACK_DIR) -endif() - #=============================================================================== include(FindPackageHandleStandardArgs) find_package_handle_standard_args(ScaLAPACK DEFAULT_MSG SCALAPACK_LIBRARY) if(SCALAPACK_FOUND AND NOT TARGET ScaLAPACK) set(SCALAPACK_LIBRARIES_ALL ${SCALAPACK_LIBRARY}) include(CheckFortranFunctionExists) set(CMAKE_REQUIRED_LIBRARIES ${SCALAPACK_LIBRARIES_ALL}) check_fortran_function_exists("blacs_gridinit" SCALAPACK_DOES_NOT_NEED_BLACS) set(CMAKE_REQUIRED_LIBRARIES) set(_blacs_dep) if(NOT SCALAPACK_DOES_NOT_NEED_BLACS) # Assuming scalapack was compiled as a static library set(SCALAPACK_LIBRARY_TYPE STATIC CACHE INTERNAL "" FORCE) find_library(BLACS_LIBRARY_C NAME blacsC - HINTS ${SCALAPACK_DIR} PATH_SUFFIXES lib) + PATHS "${SCALAPACK_DIR}" ENV SCALAPACK_DIR PATH_SUFFIXES lib) find_library(BLACS_LIBRARY_F77 NAME blacsF77 - HINTS ${SCALAPACK_DIR} PATH_SUFFIXES lib) + PATHS "${SCALAPACK_DIR}" ENV SCALAPACK_DIR PATH_SUFFIXES lib) find_library(BLACS_LIBRARY NAME blacs - HINTS ${SCALAPACK_DIR} PATH_SUFFIXES lib) + PATHS "${SCALAPACK_DIR}" ENV SCALAPACK_DIR PATH_SUFFIXES lib) mark_as_advanced( BLACS_LIBRARY_C BLACS_LIBRARY_F77 BLACS_LIBRARY ) find_package_handle_standard_args(BLACS DEFAULT_MSG BLACS_LIBRARY BLACS_LIBRARY_C BLACS_LIBRARY_F77) add_library(blacs::common ${SCALAPACK_LIBRARY_TYPE} IMPORTED GLOBAL) add_library(blacs::F77 ${SCALAPACK_LIBRARY_TYPE} IMPORTED GLOBAL) add_library(blacs::C ${SCALAPACK_LIBRARY_TYPE} IMPORTED GLOBAL) set_target_properties(blacs::F77 PROPERTIES IMPORTED_LOCATION "${BLACS_LIBRARY_F77}" IMPORTED_LINK_INTERFACE_LANGUAGES "Fortran" INTERFACE_LINK_LIBRARIES blacs::common ) set_target_properties(blacs::C PROPERTIES IMPORTED_LOCATION "${BLACS_LIBRARY_C}" INTERFACE_INCLUDE_DIRECTORIES "${SCALAPACK_INCLUDE_DIR}" IMPORTED_LINK_INTERFACE_LANGUAGES "C" INTERFACE_LINK_LIBRARIES blacs::common ) set_target_properties(blacs::common PROPERTIES IMPORTED_LOCATION "${BLACS_LIBRARY}" IMPORTED_LINK_INTERFACE_LANGUAGES "C Fortran" INTERFACE_LINK_LIBRARIES "blacs::C;blacs::F77" ) find_package(LAPACK REQUIRED) find_package(BLAS REQUIRED) list(APPEND SCALAPACK_LIBRARIES_ALL ${BLACS_LIBRARY} ${BLACS_LIBRARY_C} ${BLACS_LIBRARY_F77} ${BLACS_LIBRARY} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) set(_blacs_dep "blacs::common;${BLAS_LIBRARIES};${LAPACK_LIBRAIES}") else() set(SCALAPACK_LIBRARY_TYPE SHARED) endif() add_library(ScaLAPACK ${SCALAPACK_LIBRARY_TYPE} IMPORTED GLOBAL) set_target_properties(ScaLAPACK PROPERTIES IMPORTED_LOCATION "${SCALAPACK_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SCALAPACK_INCLUDE_DIR}" IMPORTED_LINK_INTERFACE_LANGUAGES "C Fortran" INTERFACE_LINK_LIBRARIES "${_blacs_dep}") - set(SCALAPACK_LIBRARIES ${SCALAPACK_LIBRARIES_ALL} CACHE INTERNAL "Libraries for ScaLAPACK" FORCE) + set(SCALAPACK_LIBRARIES ScaLAPACK CACHE INTERNAL "Libraries for ScaLAPACK" FORCE) endif() diff --git a/cmake/Modules/FindScotch.cmake b/cmake/Modules/FindScotch.cmake index b73aa3cdd..b9e3d0720 100644 --- a/cmake/Modules/FindScotch.cmake +++ b/cmake/Modules/FindScotch.cmake @@ -1,92 +1,242 @@ #=============================================================================== # @file FindScotch.cmake # # @author Nicolas Richart # # @date creation: Fri Oct 24 2014 # @date last modification: Wed Jan 13 2016 # # @brief The find_package file for Scotch # # @section LICENSE # # Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory # (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== -#=============================================================================== -if(NOT DEFINED SCOTCH_DIR OR NOT SCOTCH_DIR) - set(SCOTCH_DIR "" CACHE PATH "Location of Scotch library.") -endif() -mark_as_advanced(SCOTCH_DIR) +set(_SCOTCH_COMPONENTS "metis" "parmetis" "esmumps" "ptscotch") -find_library(SCOTCH_LIBRARY scotch PATHS ${SCOTCH_DIR}/lib) -find_library(SCOTCH_LIBRARY_ERR scotcherr PATHS ${SCOTCH_DIR}/lib) -find_library(SCOTCH_LIBRARY_ERREXIT scotcherrexit PATHS ${SCOTCH_DIR}/lib) -find_library(SCOTCH_LIBRARY_ESMUMPS esmumps PATHS ${SCOTCH_DIR}/lib) -find_library(SCOTCH_LIBRARY_METIS scotchmetis PATHS ${SCOTCH_DIR}/lib) -find_library(SCOTCH_LIBRARY_PARMETIS scotchparmetis PATHS ${SCOTCH_DIR}/lib) +if(NOT Scotch_FIND_COMPONENTS) + set(Scotch_FIND_COMPONENTS) +endif() -find_path(SCOTCH_INCLUDE_DIR scotch.h PATHS ${SCOTCH_DIR} +find_path(SCOTCH_INCLUDE_DIR scotch.h PATHS "${SCOTCH_DIR}" ENV SCOTCH_DIR PATH_SUFFIXES include include/scotch ) -#=============================================================================== -mark_as_advanced(SCOTCH_LIBRARY - SCOTCH_LIBRARY_ERR - SCOTCH_LIBRARY_ERREXIT - SCOTCH_LIBRARY_ESMUMPS - SCOTCH_LIBRARY_PARMETIS - SCOTCH_LIBRARY_METIS - SCOTCH_INCLUDE_DIR) - -set(SCOTCH_LIBRARIES_ALL ${SCOTCH_LIBRARY} ${SCOTCH_LIBRARY_ERR}) - -if(SCOTCH_LIBRARY_ESMUMPS) - set(SCOTCH_LIBRARIES_ALL ${SCOTCH_LIBRARY_ESMUMPS} ${SCOTCH_LIBRARIES_ALL}) -endif() - -if(SCOTCH_LIBRARY_METIS) - set(SCOTCH_LIBRARIES_ALL ${SCOTCH_LIBRARY_METIS} ${SCOTCH_LIBRARIES_ALL}) -endif() -if(SCOTCH_LIBRARY_PARMETIS) - set(SCOTCH_LIBRARIES_ALL ${SCOTCH_LIBRARY_PARMETIS} ${SCOTCH_LIBRARIES_ALL}) -endif() +find_library(SCOTCH_LIBRARY scotch PATHS "${SCOTCH_DIR}" ENV SCOTCH_DIR PATH_SUFFIXES lib) +set(_scotch_test_dir "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}") +file(WRITE "${_scotch_test_dir}/scotch_test_code.c" + "#include +#include +#include -set(SCOTCH_LIBRARIES ${SCOTCH_LIBRARIES_ALL} CACHE INTERNAL "Libraries for scotch" FORCE) +int main() { + SCOTCH_Graph graph; + SCOTCH_graphInit(&graph); + return 0; +} +") #=============================================================================== include(FindPackageHandleStandardArgs) if(CMAKE_VERSION VERSION_GREATER 2.8.12) if(SCOTCH_INCLUDE_DIR) file(STRINGS ${SCOTCH_INCLUDE_DIR}/scotch.h _versions REGEX "^#define\ +SCOTCH_(VERSION|RELEASE|PATCHLEVEL) .*") foreach(_ver ${_versions}) string(REGEX MATCH "SCOTCH_(VERSION|RELEASE|PATCHLEVEL) *([0-9.]+)" _tmp "${_ver}") set(_scotch_${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) endforeach() - set(SCOTCH_VERSION "${_scotch_VERSION}.${_scotch_PATCHLEVEL}" CACHE INTERNAL "") + set(SCOTCH_VERSION "${_scotch_VERSION}.${_scotch_RELEASE}.${_scotch_PATCHLEVEL}" CACHE INTERNAL "") endif() find_package_handle_standard_args(Scotch - REQUIRED_VARS SCOTCH_LIBRARIES SCOTCH_INCLUDE_DIR + REQUIRED_VARS SCOTCH_LIBRARY SCOTCH_INCLUDE_DIR VERSION_VAR SCOTCH_VERSION) else() find_package_handle_standard_args(Scotch DEFAULT_MSG - SCOTCH_LIBRARIES SCOTCH_INCLUDE_DIR) + SCOTCH_LIBRARY SCOTCH_INCLUDE_DIR) +endif() + +try_compile(_scotch_compiles "${_scotch_test_dir}" SOURCES "${_scotch_test_dir}/scotch_test_code.c" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${SCOTCH_INCLUDE_DIR}" + LINK_LIBRARIES ${SCOTCH_LIBRARY} + OUTPUT_VARIABLE _out) + +get_filename_component(_scotch_hint "${SCOTCH_LIBRARY}" DIRECTORY) + +if(NOT _scotch_compiles) + if(_out MATCHES "SCOTCH_errorPrint") + find_library(SCOTCH_LIBRARY_ERR scotcherr + HINTS ${_scotch_hint}) + find_library(SCOTCH_LIBRARY_ERREXIT scotcherrexit + HINTS ${_scotch_hint}) + + if(SCOTCH_LIBRARY MATCHES ".*scotch.*${CMAKE_STATIC_LIBRARY_SUFFIX}") + # Assuming scotch was compiled as a static library + set(SCOTCH_LIBRARY_TYPE STATIC CACHE INTERNAL "" FORCE) + else() + set(SCOTCH_LIBRARY_TYPE SHARED CACHE INTERNAL "" FORCE) + endif() + + if(NOT TARGET Scotch::err) + add_library(Scotch::err ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + if(NOT TARGET Scotch::errexit) + add_library(Scotch::errexit ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + + set_target_properties(Scotch::errexit PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_ERREXIT}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C") + + set_target_properties(Scotch::err PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_ERR}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + INTERFACE_LINK_LIBRARIES "Scotch::errexit") + + mark_as_advanced(SCOTCH_LIBRARY_ERR + SCOTCH_LIBRARY_ERREXIT) + + set(_scotch_link_lib INTERFACE_LINK_LIBRARIES "Scotch::err") + endif() +endif() + +if(NOT TARGET Scotch::scotch) + add_library(Scotch::scotch ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) +endif() +set_target_properties(Scotch::scotch PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + ${_scotch_link_lib}) + +set(SCOTCH_LIBRARIES Scotch::scotch CACHE INTERNAL "Libraries for Scotch" FORCE) + +mark_as_advanced(SCOTCH_LIBRARY + SCOTCH_INCLUDE_DIR + SCOTCH_LIBRARIES) + + +if("${Scotch_FIND_COMPONENTS}" MATCHES "esmumps") + find_library(SCOTCH_LIBRARY_ESMUMPS esmumps HINTS ${_scotch_hint}) + + if(NOT TARGET Scotch::esmumps) + add_library(Scotch::esmumps ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(Scotch::esmumps PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_ESMUMPS}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C") + + + mark_as_advanced(SCOTCH_LIBRARY_ESMUMPS) +endif() + +if("${Scotch_FIND_COMPONENTS}" MATCHES "metis") + find_library(SCOTCH_LIBRARY_METIS scotchmetis HINTS ${_scotch_hint}) + + if(NOT TARGET Scotch::metis) + add_library(Scotch::metis ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(Scotch::metis PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_METIS}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C") + + mark_as_advanced(SCOTCH_LIBRARY_METIS) +endif() + +if("${Scotch_FIND_COMPONENTS}" MATCHES "parmetis") + find_library(SCOTCH_LIBRARY_PARMETIS scotchparmetis HINTS ${_scotch_hint}) + + if(NOT TARGET Scotch::parmetis) + add_library(Scotch::parmetis ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(Scotch::parmetis PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_PARMETIS}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + INTERFACE_INCLUDE_DIRECTORIES "Scotch::metis") + mark_as_advanced(SCOTCH_LIBRARY_PARMETIS) +endif() + +# +##=============================================================================== +if("${Scotch_FIND_COMPONENTS}" MATCHES "ptscotch") + file(WRITE "${_scotch_test_dir}/ptscotch_test_code.c" + "#include +#include +#include +#include + +int main() { + SCOTCH_Dgraph graph; + SCOTCH_dgraphInit(&graph, MPI_COMM_WORLD); + return 0; +} +") + + find_package(MPI REQUIRED) + + find_library(SCOTCH_LIBRARY_PTSCOTCH ptscotch HINTS ${_scotch_hint}) + + try_compile(_scotch_compiles "${_scotch_test_dir}" SOURCES "${_scotch_test_dir}/ptscotch_test_code.c" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${SCOTCH_INCLUDE_DIR};${MPI_C_INCLUDE_PATH}" + LINK_LIBRARIES ${SCOTCH_LIBRARY_PTSCOTCH} ${MPI_C_LIBRARIES} + OUTPUT_VARIABLE _out) + + if(NOT _scotch_compiles) + if(_out MATCHES "SCOTCH_archExit") + set(_scotch_link_lib INTERFACE_LINK_LIBRARIES "Scotch::scotch") + endif() + endif() + + if(NOT TARGET Scotch::ptscotch) + add_library(Scotch::ptscotch ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(Scotch::ptscotch PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_PTSCOTCH}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + ${_scotch_link_lib}) + + set(PTSCOTCH_LIBRARIES Scotch::ptscotch CACHE INTERNAL "Libraries for PT-Scotch" FORCE) + + mark_as_advanced(SCOTCH_LIBRARY_PTSCOTCH + PTSCOTCH_LIBRARIES) + + if("${Scotch_FIND_COMPONENTS}" MATCHES "esmumps") + find_library(SCOTCH_LIBRARY_PTESMUMPS ptesmumps + HINTS ${_scotch_hint} PATH_SUFFIXES lib .) + + if(NOT TARGET Scotch::ptesmumps) + add_library(Scotch::ptesmumps ${SCOTCH_LIBRARY_TYPE} IMPORTED GLOBAL) + endif() + set_target_properties(Scotch::ptesmumps PROPERTIES + IMPORTED_LOCATION "${SCOTCH_LIBRARY_ESMUMPS}" + INTERFACE_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C") + + mark_as_advanced(SCOTCH_LIBRARY_PTESMUMPS) + endif() + endif() diff --git a/packages/mumps.cmake b/packages/mumps.cmake index fb5f9d401..83bccc1b7 100644 --- a/packages/mumps.cmake +++ b/packages/mumps.cmake @@ -1,100 +1,102 @@ #=============================================================================== # @file mumps.cmake # # @author Nicolas Richart # # @date creation: Mon Nov 21 2011 # @date last modification: Mon Jan 18 2016 # # @brief package description for mumps support # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== package_declare(Mumps EXTERNAL DESCRIPTION "Add Mumps support in akantu" SYSTEM ON third-party/cmake/mumps.cmake ) package_declare_sources(Mumps solver/solver_mumps.cc solver/solver_mumps.hh ) +set(_mumps_float_type ${AKANTU_FLOAT_TYPE}) + package_get_option_name(parallel _par_option) if(${_par_option}) - package_set_find_package_extra_options(Mumps ARGS COMPONENTS "parallel") + package_set_find_package_extra_options(Mumps ARGS COMPONENTS "parallel" ${_mumps_float_type}) package_add_third_party_script_variable(Mumps MUMPS_TYPE "par") package_set_package_system_dependency(Mumps deb libmumps) package_set_package_system_dependency(Mumps deb-src libmumps-dev) else() - package_set_find_package_extra_options(Mumps ARGS COMPONENTS "sequential") + package_set_find_package_extra_options(Mumps ARGS COMPONENTS "sequential" ${_mumps_float_type}) package_add_third_party_script_variable(Mumps MUMPS_TYPE "seq") package_set_package_system_dependency(Mumps deb libmumps-seq) package_set_package_system_dependency(Mumps deb-src libmumps-seq-dev) endif() package_use_system(Mumps _use_system) if(NOT _use_system) enable_language(Fortran) set(AKANTU_USE_MUMPS_VERSION "4.10.0" CACHE STRING "Default Mumps version to compile") mark_as_advanced(AKANTU_USE_MUMPS_VERSION) set_property(CACHE AKANTU_USE_MUMPS_VERSION PROPERTY STRINGS "4.9.2" "4.10.0" "5.0.0") package_get_option_name(MPI _mpi_option) if(${_mpi_option}) package_add_dependencies(Mumps ScaLAPACK MPI) endif() package_add_dependencies(Mumps Scotch BLAS) endif() package_declare_documentation(Mumps "This package enables the \\href{http://mumps.enseeiht.fr/}{MUMPS} parallel direct solver for sparce matrices." "This is necessary to solve static or implicit problems." "" "Under Ubuntu (14.04 LTS) the installation can be performed using the commands:" "" "\\begin{command}" " > sudo apt-get install libmumps-seq-dev # for sequential" " > sudo apt-get install libmumps-dev # for parallel" "\\end{command}" "" "Under Mac OS X the installation requires the following steps:" "\\begin{command}" " > sudo port install mumps" "\\end{command}" "" "If you activate the advanced option AKANTU\\_USE\\_THIRD\\_PARTY\\_MUMPS the make system of akantu can automatically compile MUMPS. For this you will have to download MUMPS from \\url{http://mumps.enseeiht.fr/} or \\url{http://graal.ens-lyon.fr/MUMPS} and place it in \\shellcode{/third-party}" ) package_declare_extra_files_to_package(MUMPS PROJECT third-party/MUMPS_4.10.0_make.inc.cmake third-party/MUMPS_5.0.0.patch third-party/MUMPS_4.10.0.patch third-party/MUMPS_4.9.2_make.inc.cmake third-party/cmake/mumps.cmake cmake/Modules/FindMumps.cmake )