Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test to verify MPI discovery #33

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion FindPETSc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,101 @@ else()
endforeach()
endif()

set(PETSC_BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/FindPETSc")

# Verify that the compiler is able to find mpi.h
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}" "
#include<mpi.h>
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
"${PETSC_BINARY_DIR}"
"${PETSC_MPI_TESTFILE}"
OUTPUT_VARIABLE PETSC_MPI_TESTOUT
)
file(WRITE "${PETSC_BINARY_DIR}/petsc-mpi.log" "${PETSC_MPI_TESTOUT}")
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<petscsys.h>
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
)
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_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) ")
Expand Down Expand Up @@ -316,7 +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 could not be used, maybe the install is broken.")
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)
Expand Down