From 18b6b4c5666e2e1bdbbe52a0f374ff7a6623157b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvk?= Date: Tue, 16 Sep 2014 11:37:06 +0000 Subject: [PATCH 1/6] Fixes status message when PETSc couldn't be found. --- cmake/Modules/FindPetsc.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindPetsc.cmake b/cmake/Modules/FindPetsc.cmake index 87ba3c20..ab45ffb5 100644 --- a/cmake/Modules/FindPetsc.cmake +++ b/cmake/Modules/FindPetsc.cmake @@ -96,7 +96,7 @@ if (NOT PETSC_LIBRARY) ) endif() if(NOT PETSC_LIBRARY) - message(STATUS "Directory with the SuperLU library not found") + message(STATUS "Could not find the PETSc library") return() endif() list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_LIBRARY}") From 3204518bcc246445b03edf62439dfd2879836554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvk?= Date: Tue, 16 Sep 2014 11:37:59 +0000 Subject: [PATCH 2/6] Removes broken conditional check. The FindPetsc module would check for a PETSC_ROOT and not attempt to look for mpi and the petsc header if this was not set, which it in most cases won't be. If the variable is set then the conditional include is redundant, as it will search the explicitly passed paths first anyways. --- cmake/Modules/FindPetsc.cmake | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmake/Modules/FindPetsc.cmake b/cmake/Modules/FindPetsc.cmake index ab45ffb5..63c2b652 100644 --- a/cmake/Modules/FindPetsc.cmake +++ b/cmake/Modules/FindPetsc.cmake @@ -67,24 +67,20 @@ if (Petsc_ROOT) set (PETSC_ROOT "${Petsc_ROOT}") endif (Petsc_ROOT) if (NOT PETSC_NORMAL_INCLUDE_DIR) - if (PETSC_ROOT) find_path (PETSC_NORMAL_INCLUDE_DIR NAMES "petsc.h" PATHS ${PETSC_ROOT} PATH_SUFFIXES "petsc-3.4.4" "include" NO_DEFAULT_PATH ) - endif (PETSC_ROOT) endif (NOT PETSC_NORMAL_INCLUDE_DIR) if (NOT PETSC_MPIUNI_INCLUDE_DIR) - if (PETSC_ROOT) find_path (PETSC_MPIUNI_INCLUDE_DIR NAMES "mpi.h" PATHS ${PETSC_ROOT}/include PATH_SUFFIXES "mpiuni" NO_DEFAULT_PATH ) - endif (PETSC_ROOT) endif (NOT PETSC_MPIUNI_INCLUDE_DIR) # look for actual Petsc library if (NOT PETSC_LIBRARY) From b595dd0abd1a5d1d080ab25fe394d4da66a9a61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvk?= Date: Tue, 16 Sep 2014 11:39:18 +0000 Subject: [PATCH 3/6] FindPets searches default paths w/ general namings Removed the NO_DEFAULT_PATH flag as this really isn't working for most systems (where PETSc will be installed from a repository and in /usr or /). Path suffix parameters extended to accept more version-less configs too, to be compatible with a default PETSc (debian style) install. --- cmake/Modules/FindPetsc.cmake | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmake/Modules/FindPetsc.cmake b/cmake/Modules/FindPetsc.cmake index 63c2b652..590097b0 100644 --- a/cmake/Modules/FindPetsc.cmake +++ b/cmake/Modules/FindPetsc.cmake @@ -70,16 +70,14 @@ if (NOT PETSC_NORMAL_INCLUDE_DIR) find_path (PETSC_NORMAL_INCLUDE_DIR NAMES "petsc.h" PATHS ${PETSC_ROOT} - PATH_SUFFIXES "petsc-3.4.4" "include" - NO_DEFAULT_PATH + PATH_SUFFIXES "petsc-3.4.4" "include" "petsc" ) endif (NOT PETSC_NORMAL_INCLUDE_DIR) if (NOT PETSC_MPIUNI_INCLUDE_DIR) find_path (PETSC_MPIUNI_INCLUDE_DIR NAMES "mpi.h" - PATHS ${PETSC_ROOT}/include - PATH_SUFFIXES "mpiuni" - NO_DEFAULT_PATH + PATHS ${PETSC_ROOT} + PATH_SUFFIXES "mpiuni" "mpi" ) endif (NOT PETSC_MPIUNI_INCLUDE_DIR) # look for actual Petsc library @@ -88,7 +86,6 @@ if (NOT PETSC_LIBRARY) NAMES "petsc-3.4.3" "petsc-3.4.4" "petsc" PATHS ${PETSC_ROOT} PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" - NO_DEFAULT_PATH ) endif() if(NOT PETSC_LIBRARY) From 95357155e42ff7d19880b8770b3b4bc1f34dab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Wed, 17 Sep 2014 13:33:41 +0200 Subject: [PATCH 4/6] FindPetsc uses system-provided MPI if available When building with USE_MPI=ON the FindPetsc now uses the system provided MPI if available. Falls back to looking for the PETSc provided unimpi for sequential builds. --- cmake/Modules/FindPetsc.cmake | 49 ++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/cmake/Modules/FindPetsc.cmake b/cmake/Modules/FindPetsc.cmake index 590097b0..5eeb96e7 100644 --- a/cmake/Modules/FindPetsc.cmake +++ b/cmake/Modules/FindPetsc.cmake @@ -73,13 +73,41 @@ if (NOT PETSC_NORMAL_INCLUDE_DIR) PATH_SUFFIXES "petsc-3.4.4" "include" "petsc" ) endif (NOT PETSC_NORMAL_INCLUDE_DIR) -if (NOT PETSC_MPIUNI_INCLUDE_DIR) - find_path (PETSC_MPIUNI_INCLUDE_DIR - NAMES "mpi.h" - PATHS ${PETSC_ROOT} - PATH_SUFFIXES "mpiuni" "mpi" - ) -endif (NOT PETSC_MPIUNI_INCLUDE_DIR) + +# if parallel computing is explicitly enabled - reuse the paths and links from +# OpmMainLib + OpmFind +# this needs to be called explicitly as FindPetsc runs before OpmMainLib starts +# looking for MPI (for some reason). Ideally this isn't necessary +if(USE_MPI) + find_package(MPI) +endif() + +set(PETSC_MPI_FOUND ${MPI_FOUND}) +set(PETSC_MPI_INCLUDE_DIRS ${MPI_INCLUDE_PATH}) +set(PETSC_MPI_LIBRARIES ${MPI_LIBRARIES}) + +# fallback - use the petsc provided implementation of serial MPI. +if (NOT PETSC_MPI_INCLUDE_DIRS) + message(STATUS "Building without MPI support - looking for PETSc provided serial implementation") + find_path (PETSC_MPI_INCLUDE_DIRS + NAMES "mpi.h" + PATHS ${PETSC_ROOT}/include + PATH_SUFFIXES "mpiuni" + ) + + if(PETSC_MPI_INCLUDE_DIRS) + # not setting special linkage + set(PETSC_MPI_FOUND 1) + endif(PETSC_MPI_INCLUDE_DIRS) + +endif(NOT PETSC_MPI_INCLUDE_DIRS) + +# couldn't find any usable mpi implementation - abort +if(NOT PETSC_MPI_FOUND) + message(STATUS "Could not find any suitable MPI implementation. Is PETSC_ROOT set?") + return() +endif() + # look for actual Petsc library if (NOT PETSC_LIBRARY) find_library(PETSC_LIBRARY @@ -92,10 +120,11 @@ if(NOT PETSC_LIBRARY) message(STATUS "Could not find the PETSc library") return() endif() -list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_LIBRARY}") -if (PETSC_MPIUNI_INCLUDE_DIR AND PETSC_NORMAL_INCLUDE_DIR) - list (APPEND PETSC_INCLUDE_DIR ${PETSC_MPIUNI_INCLUDE_DIR} ${PETSC_NORMAL_INCLUDE_DIR}) +list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_LIBRARY}" "${PETSC_MPI_LIBRARIES}") + +if (PETSC_MPI_INCLUDE_DIRS AND PETSC_NORMAL_INCLUDE_DIR) + list (APPEND PETSC_INCLUDE_DIR ${PETSC_MPI_INCLUDE_DIRS} ${PETSC_NORMAL_INCLUDE_DIR}) endif() include(FindPackageHandleStandardArgs) From 60ca9698ba368b1458f4d2387d5040a10b82d811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 19 Sep 2014 11:40:20 +0200 Subject: [PATCH 5/6] PETSC_ROOT now sets NO_DEFAULT_PATH Allows a specific PETSC_ROOT to override and replace default search paths. Now, if PETSC_ROOT is passed and the find_library calls cannot find the libraries, the makefile will only search in user provided directories. --- cmake/Modules/FindPetsc.cmake | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/FindPetsc.cmake b/cmake/Modules/FindPetsc.cmake index 5eeb96e7..e778edda 100644 --- a/cmake/Modules/FindPetsc.cmake +++ b/cmake/Modules/FindPetsc.cmake @@ -20,6 +20,13 @@ if (CMAKE_SIZEOF_VOID_P) math (EXPR _BITS "8 * ${CMAKE_SIZEOF_VOID_P}") endif (CMAKE_SIZEOF_VOID_P) +# if PETSC_ROOT is set, then this is the only place searched for petsc headers +# and includes +set(_no_default_path "") +if(PETSC_ROOT) + set (_no_default_path "NO_DEFAULT_PATH") +endif() + # look for a system-wide BLAS library find_package(BLAS QUIET) set(PETSC_BLAS_LIBRARY "") @@ -30,7 +37,7 @@ elseif(PETSC_ROOT) NAME "blas" PATH ${PETSC_ROOT} PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" - NO_DEFAULT_PATH) + ${_no_default_path} ) endif() # print message if there was still no blas found! if(NOT BLAS_FOUND AND NOT PETSC_BLAS_LIBRARY) @@ -48,7 +55,7 @@ elseif(PETSC_ROOT) NAME "lapack" PATH ${PETSC_ROOT} PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" - NO_DEFAULT_PATH) + ${_no_default_path}) endif() # print message if there was still no blas found! if(NOT LAPACK_FOUND AND NOT PETSC_LAPACK_LIBRARY) @@ -66,11 +73,13 @@ list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_X11_LIBRARY}") if (Petsc_ROOT) set (PETSC_ROOT "${Petsc_ROOT}") endif (Petsc_ROOT) + if (NOT PETSC_NORMAL_INCLUDE_DIR) find_path (PETSC_NORMAL_INCLUDE_DIR NAMES "petsc.h" PATHS ${PETSC_ROOT} PATH_SUFFIXES "petsc-3.4.4" "include" "petsc" + ${_no_default_path} ) endif (NOT PETSC_NORMAL_INCLUDE_DIR) @@ -93,10 +102,10 @@ if (NOT PETSC_MPI_INCLUDE_DIRS) NAMES "mpi.h" PATHS ${PETSC_ROOT}/include PATH_SUFFIXES "mpiuni" + ${_no_default_path} ) if(PETSC_MPI_INCLUDE_DIRS) - # not setting special linkage set(PETSC_MPI_FOUND 1) endif(PETSC_MPI_INCLUDE_DIRS) @@ -104,7 +113,7 @@ endif(NOT PETSC_MPI_INCLUDE_DIRS) # couldn't find any usable mpi implementation - abort if(NOT PETSC_MPI_FOUND) - message(STATUS "Could not find any suitable MPI implementation. Is PETSC_ROOT set?") + message(STATUS "Could not find any suitable MPI implementation.") return() endif() @@ -114,6 +123,7 @@ if (NOT PETSC_LIBRARY) NAMES "petsc-3.4.3" "petsc-3.4.4" "petsc" PATHS ${PETSC_ROOT} PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" + ${_no_default_path} ) endif() if(NOT PETSC_LIBRARY) From 48b54d321abcdf9de4adaaf4f51f4090aca838a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 19 Sep 2014 12:32:50 +0200 Subject: [PATCH 6/6] Simplifcations in FindPetsc logic Removes a lot of the conditionals in the makefile. As reflected in the comments, find_* won't run if the target variable is already set, and appending empty list elements changes nothing. In order to make reading the file easier these conditionals have mostly been removed. --- cmake/Modules/FindPetsc.cmake | 75 ++++++++++++++++------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/cmake/Modules/FindPetsc.cmake b/cmake/Modules/FindPetsc.cmake index e778edda..9c6dd686 100644 --- a/cmake/Modules/FindPetsc.cmake +++ b/cmake/Modules/FindPetsc.cmake @@ -28,35 +28,38 @@ if(PETSC_ROOT) endif() # look for a system-wide BLAS library -find_package(BLAS QUIET) set(PETSC_BLAS_LIBRARY "") -if (BLAS_FOUND) - list(APPEND PETSC_BLAS_LIBRARY "${BLAS_LIBRARIES}") -elseif(PETSC_ROOT) - find_library(PETST_BLAS_LIBRARY - NAME "blas" - PATH ${PETSC_ROOT} - PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" - ${_no_default_path} ) -endif() +find_package(BLAS QUIET) +list(APPEND PETSC_BLAS_LIBRARY "${BLAS_LIBRARIES}") + +# if BLAS wasn't found, look for it in PETSC_ROOT. Won't search if +# PETSC_BLAS_LIBRARY is set. +find_library(PETSC_BLAS_LIBRARY + NAME "blas" + PATH ${PETSC_ROOT} + PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" + ${_no_default_path} + ) + # print message if there was still no blas found! if(NOT BLAS_FOUND AND NOT PETSC_BLAS_LIBRARY) message(STATUS "BLAS not found but required for PETSC") return() endif() list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_BLAS_LIBRARY}") -find_package(LAPACK QUIET) set(PETSC_LAPACK_LIBRARY "") -if (LAPACK_FOUND) - list(APPEND PETSC_LAPACK_LIBRARY "${LAPACK_LIBRARIES}") -elseif(PETSC_ROOT) - find_library(PETST_LAPACK_LIBRARY - NAME "lapack" - PATH ${PETSC_ROOT} - PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" - ${_no_default_path}) -endif() +find_package(LAPACK QUIET) +list(APPEND PETSC_LAPACK_LIBRARY "${LAPACK_LIBRARIES}") + +# if LAPACK wasn't found, look for it in PETSC_ROOT +find_library(PETSC_LAPACK_LIBRARY + NAME "lapack" + PATH ${PETSC_ROOT} + PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" + ${_no_default_path} + ) + # print message if there was still no blas found! if(NOT LAPACK_FOUND AND NOT PETSC_LAPACK_LIBRARY) message(STATUS "LAPACK not found but required for PETSC") @@ -69,19 +72,18 @@ if (X11_FOUND) list(APPEND PETSC_X11_LIBRARY "${X11_LIBRARIES}") endif() list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_X11_LIBRARY}") + # only probe if we haven't a path in our cache if (Petsc_ROOT) set (PETSC_ROOT "${Petsc_ROOT}") endif (Petsc_ROOT) -if (NOT PETSC_NORMAL_INCLUDE_DIR) - find_path (PETSC_NORMAL_INCLUDE_DIR - NAMES "petsc.h" - PATHS ${PETSC_ROOT} - PATH_SUFFIXES "petsc-3.4.4" "include" "petsc" - ${_no_default_path} - ) -endif (NOT PETSC_NORMAL_INCLUDE_DIR) +find_path (PETSC_NORMAL_INCLUDE_DIR + NAMES "petsc.h" + PATHS ${PETSC_ROOT} + PATH_SUFFIXES "petsc-3.4.4" "include" "petsc" + ${_no_default_path} + ) # if parallel computing is explicitly enabled - reuse the paths and links from # OpmMainLib + OpmFind @@ -118,14 +120,13 @@ if(NOT PETSC_MPI_FOUND) endif() # look for actual Petsc library -if (NOT PETSC_LIBRARY) - find_library(PETSC_LIBRARY +find_library(PETSC_LIBRARY NAMES "petsc-3.4.3" "petsc-3.4.4" "petsc" PATHS ${PETSC_ROOT} PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" ${_no_default_path} ) -endif() + if(NOT PETSC_LIBRARY) message(STATUS "Could not find the PETSc library") return() @@ -143,18 +144,10 @@ mark_as_advanced(PETSC_INCLUDE_DIR PETSC_LIBRARY) # if both headers and library are found, store results if(PETSC_FOUND) - set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIR}) + set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIR}) + set(PETSC_LIBRARIES ${PETSC_LIBRARY}) - set(PETSC_LIBRARIES ${PETSC_LIBRARY}) - - if (PETSC_BLAS_LIBRARY) list(APPEND PETSC_LIBRARIES ${PETSC_BLAS_LIBRARY}) - endif() - if (PETSC_LAPACK_LIBRARY) list(APPEND PETSC_LIBRARIES ${PETSC_LAPACK_LIBRARY}) - endif() - if (PETSC_X11_LIBRARY) list(APPEND PETSC_LIBRARIES ${PETSC_X11_LIBRARY}) - endif() endif() -