From 69a7b2e8dbee9de930462e62cb02097bd193e712 Mon Sep 17 00:00:00 2001 From: Frederic Simonis Date: Thu, 13 Dec 2018 16:49:00 +0100 Subject: [PATCH 1/3] Add Test to verify MPI discovery --- FindPETSc.cmake | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/FindPETSc.cmake b/FindPETSc.cmake index 41e02d9..bb7343d 100644 --- a/FindPETSc.cmake +++ b/FindPETSc.cmake @@ -54,6 +54,44 @@ else() endforeach() endif() + +# Verify that the compiler is able to find mpi.h +set(PETSC_BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/FindPETSc") +set(PETSC_MPI_TESTFILE "${PETSC_BINARY_DIR}/petsc-mpi.c") +if(PETSC_LANGUAGE_BINDINGS STREQUAL "CXX") + set(PETSC_MPI_TESTFILE "${PETSC_MPI_TESTFILE}pp") +endif() + +file (WRITE "${PETSC_MPI_TESTFILE}" " +#include +int main (int argc, char* argv[]) { + return 0; +} +") + +message(STATUS "Performing Test petsc-mpi") +try_compile( + PETSC_MPI_COMPILES + "${CMAKE_CURRENT_BINARY_DIR}" + "${PETSC_MPI_TESTFILE}" + OUTPUT_VARIABLE PETSC_MPI_TESTOUT + ) +if(NOT PETSC_MPI_COMPILES) + file(WRITE "${PETSC_BINARY_DIR}/petsc-mpi.log" "${PETSC_MPI_TESTOUT}") + message(STATUS "Performing Test petsc-mpi - Failure") + message(FATAL_ERROR + "Compilation of the petsc mpi test failed. This indicates that the compiler cannot find mpi.h. " + "Make sure to set the compiler to the compiler wrapper provided by your MPI version prior to calling this script.\n" + "Logfile of the compilation: ${PETSC_BINARY_DIR}/petsc-mpi.log" + ) +else() + message(STATUS "Performing Test petsc-mpi - Success") +endif() +unset(PETSC_MPI_TESTFILE) +unset(PETSC_MPI_TESTOUT) +unset(PETSC_MPI_COMPILES) + + function (petsc_get_version) if (EXISTS "${PETSC_DIR}/include/petscversion.h") file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") From 6e0581c8ae0642a82efb1b5605584be534371231 Mon Sep 17 00:00:00 2001 From: Frederic Simonis Date: Fri, 14 Dec 2018 14:18:24 +0100 Subject: [PATCH 2/3] Add diagnostic checks on failure Extend the MPI check to detect missing MPI libs. Turned the MPI check into a function. Added function to check the petscsys include. Added simple diagnostics on failure. --- FindPETSc.cmake | 107 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/FindPETSc.cmake b/FindPETSc.cmake index bb7343d..c4da7ee 100644 --- a/FindPETSc.cmake +++ b/FindPETSc.cmake @@ -54,42 +54,70 @@ else() endforeach() endif() +set(PETSC_BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/FindPETSc") # Verify that the compiler is able to find mpi.h -set(PETSC_BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/FindPETSc") -set(PETSC_MPI_TESTFILE "${PETSC_BINARY_DIR}/petsc-mpi.c") -if(PETSC_LANGUAGE_BINDINGS STREQUAL "CXX") - set(PETSC_MPI_TESTFILE "${PETSC_MPI_TESTFILE}pp") -endif() +function (petsc_check_mpi) + set(PETSC_MPI_TESTFILE "${PETSC_BINARY_DIR}/petsc-mpi.c") + if(PETSC_LANGUAGE_BINDINGS STREQUAL "CXX") + set(PETSC_MPI_TESTFILE "${PETSC_MPI_TESTFILE}pp") + endif() -file (WRITE "${PETSC_MPI_TESTFILE}" " + file (WRITE "${PETSC_MPI_TESTFILE}" " #include -int main (int argc, char* argv[]) { - return 0; +int main (int argc, char** argv[]) { +MPI_Init(NULL, NULL); +MPI_Finalize(); +return 0; } ") -message(STATUS "Performing Test petsc-mpi") -try_compile( - PETSC_MPI_COMPILES - "${CMAKE_CURRENT_BINARY_DIR}" - "${PETSC_MPI_TESTFILE}" - OUTPUT_VARIABLE PETSC_MPI_TESTOUT - ) -if(NOT PETSC_MPI_COMPILES) + message(STATUS "Performing Test petsc-mpi") + try_compile( + PETSC_MPI_COMPILES + "${PETSC_BINARY_DIR}" + "${PETSC_MPI_TESTFILE}" + OUTPUT_VARIABLE PETSC_MPI_TESTOUT + ) file(WRITE "${PETSC_BINARY_DIR}/petsc-mpi.log" "${PETSC_MPI_TESTOUT}") - message(STATUS "Performing Test petsc-mpi - Failure") - message(FATAL_ERROR - "Compilation of the petsc mpi test failed. This indicates that the compiler cannot find mpi.h. " - "Make sure to set the compiler to the compiler wrapper provided by your MPI version prior to calling this script.\n" - "Logfile of the compilation: ${PETSC_BINARY_DIR}/petsc-mpi.log" + if(NOT PETSC_MPI_COMPILES) + message(STATUS "Performing Test petsc-mpi - Failure") + else() + message(STATUS "Performing Test petsc-mpi - Success") + endif() + set(PETSC_MPI_WORKS "${PETSC_MPI_COMPILES}" PARENT_SCOPE) +endfunction(petsc_check_mpi) + +# Verify that the compiler is able to find mpi.h +function (petsc_check_header includes) + set(PETSC_HEADER_TESTFILE "${PETSC_BINARY_DIR}/petsc-header.c") + if(PETSC_LANGUAGE_BINDINGS STREQUAL "CXX") + set(PETSC_HEADER_TESTFILE "${PETSC_HEADER_TESTFILE}pp") + endif() + + file (WRITE "${PETSC_HEADER_TESTFILE}" " +#include +int main (int argc, char* argv[]) { +return 0; +} +") + + message(STATUS "Performing Test petsc-header") + try_compile( + PETSC_HEADER_COMPILES + "${PETSC_BINARY_DIR}" + "${PETSC_HEADER_TESTFILE}" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:LIST=${includes}" + OUTPUT_VARIABLE PETSC_HEADER_TESTOUT ) -else() - message(STATUS "Performing Test petsc-mpi - Success") -endif() -unset(PETSC_MPI_TESTFILE) -unset(PETSC_MPI_TESTOUT) -unset(PETSC_MPI_COMPILES) + file(WRITE "${PETSC_BINARY_DIR}/petsc-header.log" "${PETSC_HEADER_TESTOUT}") + if(NOT PETSC_HEADER_COMPILES) + message(STATUS "Performing Test petsc-header - Failure") + else() + message(STATUS "Performing Test petsc-header - Success") + endif() + set(PETSC_HEADER_WORKS "${PETSC_HEADER_COMPILES}" PARENT_SCOPE) +endfunction(petsc_check_header) function (petsc_get_version) @@ -354,7 +382,30 @@ int main(int argc,char *argv[]) { if (petsc_works_all) # We fail anyways message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") else (petsc_works_all) # We fail anyways - message (STATUS "PETSc could not be used, maybe the install is broken.") + message (STATUS "PETSc does not work. Running more tests to find out why:") + petsc_check_header("${petsc_includes_all}") + petsc_check_mpi() + + if (PETSC_HEADER_WORKS) + if (PETSC_MPI_WORKS) + message (STATUS "PETSc include was found and MPI works too. The PETSc libraries could be the problem. Please check the general log.") + else (PETSC_MPI_WORKS) + message (STATUS "MPI test failed. If PETSc was built with MPI please check if the compiler is set to the compiler wrapper provided by your MPI implementation.") + endif (PETSC_MPI_WORKS) + else (PETSC_HEADER_WORKS) + if (PETSC_MPI_WORKS) + message (STATUS "PETSc includes may be incorrect. Please check the log of the header check.") + else (PETSC_MPI_WORKS) + message (STATUS "PETSc includes are incorrect and MPI failed. If PETSc was built with MPI please check if the compiler is set to the compiler wrapper provided by your MPI implementation.") + endif (PETSC_MPI_WORKS) + endif (PETSC_HEADER_WORKS) + message(STATUS " Settings used for the final test:\n" + " Includes: ${petsc_includes_all}\n" + " Libraries:${PETSC_LIBRARIES_ALL}\n") + message(STATUS " Related log files:\n" + "General: ${CMAKE_BINARY_DIR}/CMakeError.log\n" + "Header Check: ${PETSC_BINARY_DIR}/petsc-header.log\n" + "MPI Check: ${PETSC_BINARY_DIR}/petsc-mpi.log\n") endif (petsc_works_all) endif (petsc_works_alllibraries) endif (petsc_works_allincludes) From 906044fdd7649bb09a971474d8b73db1a99e50bd Mon Sep 17 00:00:00 2001 From: Frederic Simonis Date: Fri, 14 Dec 2018 14:52:29 +0100 Subject: [PATCH 3/3] Adjust Verbosity Skip diagnostics on QUIET Run tests, but skip diagnostics output if not REQUIRED Refactor diagnostics into separate function --- FindPETSc.cmake | 57 ++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/FindPETSc.cmake b/FindPETSc.cmake index c4da7ee..cfe8a27 100644 --- a/FindPETSc.cmake +++ b/FindPETSc.cmake @@ -120,6 +120,35 @@ return 0; endfunction(petsc_check_header) +function (petsc_run_diagnostics includes libraries) + message (STATUS "Running more tests to create basic diagnostics:") + petsc_check_header("${includes}") + petsc_check_mpi() + if (PETSc_FIND_REQUIRED) + if (PETSC_HEADER_WORKS) + if (PETSC_MPI_WORKS) + message (STATUS "PETSc include was found and MPI works too. The PETSc libraries could be the problem. Please check the general log.") + else (PETSC_MPI_WORKS) + message (STATUS "MPI test failed. If PETSc was built with MPI please check if the compiler is set to the compiler wrapper provided by your MPI implementation.") + endif (PETSC_MPI_WORKS) + else (PETSC_HEADER_WORKS) + if (PETSC_MPI_WORKS) + message (STATUS "PETSc includes may be incorrect. Please check the log of the header check.") + else (PETSC_MPI_WORKS) + message (STATUS "PETSc includes are incorrect and MPI failed. If PETSc was built with MPI please check if the compiler is set to the compiler wrapper provided by your MPI implementation.") + endif (PETSC_MPI_WORKS) + endif (PETSC_HEADER_WORKS) + message(STATUS " Settings used for the final test:\n" + " Includes: ${includes}\n" + " Libraries:${libraries}\n") + message(STATUS " Related log files:\n" + "General: ${CMAKE_BINARY_DIR}/CMakeError.log\n" + "Header Check: ${PETSC_BINARY_DIR}/petsc-header.log\n" + "MPI Check: ${PETSC_BINARY_DIR}/petsc-mpi.log\n") + endif (PETSc_FIND_REQUIRED) +endfunction (petsc_run_diagnostics) + + function (petsc_get_version) if (EXISTS "${PETSC_DIR}/include/petscversion.h") file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") @@ -382,30 +411,10 @@ int main(int argc,char *argv[]) { if (petsc_works_all) # We fail anyways message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") else (petsc_works_all) # We fail anyways - message (STATUS "PETSc does not work. Running more tests to find out why:") - petsc_check_header("${petsc_includes_all}") - petsc_check_mpi() - - if (PETSC_HEADER_WORKS) - if (PETSC_MPI_WORKS) - message (STATUS "PETSc include was found and MPI works too. The PETSc libraries could be the problem. Please check the general log.") - else (PETSC_MPI_WORKS) - message (STATUS "MPI test failed. If PETSc was built with MPI please check if the compiler is set to the compiler wrapper provided by your MPI implementation.") - endif (PETSC_MPI_WORKS) - else (PETSC_HEADER_WORKS) - if (PETSC_MPI_WORKS) - message (STATUS "PETSc includes may be incorrect. Please check the log of the header check.") - else (PETSC_MPI_WORKS) - message (STATUS "PETSc includes are incorrect and MPI failed. If PETSc was built with MPI please check if the compiler is set to the compiler wrapper provided by your MPI implementation.") - endif (PETSC_MPI_WORKS) - endif (PETSC_HEADER_WORKS) - message(STATUS " Settings used for the final test:\n" - " Includes: ${petsc_includes_all}\n" - " Libraries:${PETSC_LIBRARIES_ALL}\n") - message(STATUS " Related log files:\n" - "General: ${CMAKE_BINARY_DIR}/CMakeError.log\n" - "Header Check: ${PETSC_BINARY_DIR}/petsc-header.log\n" - "MPI Check: ${PETSC_BINARY_DIR}/petsc-mpi.log\n") + message (STATUS "PETSc does not work. Maybe the install is broken.") + if (NOT PETSc_FIND_QUIETLY) + petsc_run_diagnostics("${petsc_includes_all}" "${PETSC_LIBRARIES_ALL}") + endif (NOT PETSc_FIND_QUIETLY) endif (petsc_works_all) endif (petsc_works_alllibraries) endif (petsc_works_allincludes)