diff --git a/CMakeLists.txt b/CMakeLists.txt index d658ad70..8aaf1c87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(amg4psblas VERSION 1.0 LANGUAGES C Fortran) +project(amg4psblas VERSION 1.0 LANGUAGES C CXX Fortran) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") @@ -39,7 +39,7 @@ set(LIBDIR "${PSBLAS_INSTALL_DIR}/${PSB_CMAKE_INSTALL_LIBDIR}") # Include directories for the project -include_directories(${PSBLAS_INSTALL_DIR}) +include_directories(${PSBLAS_INSTALL_DIR} ${MPI_INCLUDE_PATH} ) # Include directories for the Fortran compiler @@ -177,6 +177,65 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) #---------------------------------- # Determine if we're using Open MPI #--------------------------------- + + + +find_package( MPI REQUIRED Fortran ) + +if(MPI_FOUND) + #----------------------------------------------- + # Work around an issue present on fedora systems + #----------------------------------------------- + if( (MPI_C_LINK_FLAGS MATCHES "noexecstack") OR (MPI_Fortran_LINK_FLAGS MATCHES "noexecstack") ) + message ( WARNING + "The `noexecstack` linker flag was found in the MPI__LINK_FLAGS variable. This is +known to cause segmentation faults for some Fortran codes. See, e.g., +https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71729 or +https://github.com/sourceryinstitute/OpenCoarrays/issues/317. + +`noexecstack` is being replaced with `execstack`" + ) + string(REPLACE "noexecstack" + "execstack" MPI_C_LINK_FLAGS_FIXED ${MPI_C_LINK_FLAGS}) + string(REPLACE "noexecstack" + "execstack" MPI_Fortran_LINK_FLAGS_FIXED ${MPI_Fortran_LINK_FLAGS}) + set(MPI_C_LINK_FLAGS "${MPI_C_LINK_FLAGS_FIXED}" CACHE STRING + "MPI C linking flags" FORCE) + set(MPI_Fortran_LINK_FLAGS "${MPI_Fortran_LINK_FLAGS_FIXED}" CACHE STRING + "MPI Fortran linking flags" FORCE) + + endif() + + message(STATUS "Found MPI: ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES}") + + #---------------- + # Setup MPI flags + #---------------- + list(REMOVE_DUPLICATES MPI_Fortran_INCLUDE_PATH) + set(CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS}) + set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS}) + set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}) + set(CMAKE_Fortran_LINK_FLAGS ${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS}) + include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH}) +message(STATUS "${MPI_C_INCLUDE_PATH}; ${MPI_Fortran_INCLUDE_PATH};; ${CMAKE_Fortran_LINK_FLAGS} ;") + if(MPI_Fortran_HAVE_F90_MODULE OR MPI_Fortran_HAVE_F08_MODULE) + add_compile_options(-DPSB_MPI_MOD) + message(STATUS "-DPSB_MPI_MOD") + #add_compile_options(-DSERIAL_MPI) # Is it right?? + #message(STATUS "-DSERIAL_MPI") + endif() + set(PSB_SERIAL_MPI OFF) + +else() + message(STATUS "MPI not found, serial ahead") + add_compile_options(-DPSB_SERIAL_MPI) + add_compile_options(-DPSB_MPI_MOD) + set(PSB_SERIAL_MPI ON) + set(CSERIALMPI "#define PSB_SERIAL_MPI") +endif() + + +message(STATUS "++++++++++++++++++++++++++++++ MPI") if(MPI_FOUND) execute_process(COMMAND ${MPIEXEC} --version OUTPUT_VARIABLE mpi_version_out) @@ -184,8 +243,36 @@ if(MPI_FOUND) message( STATUS "OpenMPI detected") set ( openmpi true ) endif() -endif() + + + set(MPI_H_COPIED FALSE) + set(MPI_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include") # Define the include directory + + # Create the include directory if it doesn't exist + file(MAKE_DIRECTORY "${MPI_INCLUDE_DIR}") + + foreach(path IN LISTS MPI_INCLUDE_PATH) + # Construct the full path to the mpi.h file + set(mpi_h_path "${path}/mpi.h") + + # Check if the mpi.h file exists + if(EXISTS "${mpi_h_path}") + # Copy the mpi.h file to the include directory + file(COPY "${mpi_h_path}" DESTINATION "${MPI_INCLUDE_DIR}") + message(STATUS "Copied mpi.h from ${mpi_h_path} to ${MPI_INCLUDE_DIR}") + set(MPI_H_COPIED TRUE) + break() # Exit the loop once we've copied the file + endif() + endforeach() + + if(NOT MPI_H_COPIED) + message(WARNING "mpi.h not found in any of the specified paths: ${MPI_INCLUDE_PATH}") + endif() + # Add the created include directory to the project's include directories + include_directories("${MPI_INCLUDE_DIR}") +endif() +message(STATUS "******************************** MPI") #------------------------------------------ @@ -215,13 +302,20 @@ include(${CMAKE_CURRENT_LIST_DIR}/amgprec/CMakeLists.txt) # include amgprec_sou include_directories("${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}") add_library(amgprec_C OBJECT ${amgprec_source_C_files}) +add_library(amgprec_CPP OBJECT ${amgprec_source_CPP_files}) target_link_libraries(amgprec_C #PUBLIC ${LAPACK_LINKER_FLAGS} ${LAPACK_LIBRARIES} ${LAPACK95_LIBRARIES} #PUBLIC ${BLAS_LINKER_FLAGS} ${BLAS_LIBRARIES} ${BLAS95_LIBRARIES} psblas::util psblas::linsolve psblas::prec psblas::ext psblas::cbind psblas::base) #TODO check actual libraries needed -add_library(amgprec ${amgprec_source_files} $) +target_link_libraries(amgprec_CPP + #PUBLIC ${LAPACK_LINKER_FLAGS} ${LAPACK_LIBRARIES} ${LAPACK95_LIBRARIES} + #PUBLIC ${BLAS_LINKER_FLAGS} ${BLAS_LIBRARIES} ${BLAS95_LIBRARIES} + psblas::util psblas::linsolve psblas::prec psblas::ext psblas::cbind psblas::base + ${MPI_LIBRARIES} ) #TODO check actual libraries needed + +add_library(amgprec ${amgprec_source_files} $ $) set_target_properties(amgprec PROPERTIES diff --git a/amgprec/CMakeLists.txt b/amgprec/CMakeLists.txt index 87a91b72..a0fd8f20 100644 --- a/amgprec/CMakeLists.txt +++ b/amgprec/CMakeLists.txt @@ -875,6 +875,32 @@ list(APPEND AMG_amgprec_source_C_files impl/amg_dslud_interface.c) list(APPEND AMG_amgprec_source_C_files impl/amg_zumf_interface.c) list(APPEND AMG_amgprec_source_C_files impl/amg_zslud_interface.c) + +set(AMG_amgprec_source_CPP_files +impl/aggregator/computeCandidateMate.cpp +impl/aggregator/processExposedVertex.cpp +impl/aggregator/processMatchedVertices.cpp +impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateCMP.cpp +impl/aggregator/processCrossEdge.cpp +impl/aggregator/findOwnerOfGhost.cpp +impl/aggregator/MatchBoxPC.cpp +impl/aggregator/queueTransfer.cpp +impl/aggregator/clean.cpp +impl/aggregator/algoDistEdgeApproxDomEdgesLinearSearchMesgBndlSmallMateC.cpp +impl/aggregator/extractUChunk.cpp +impl/aggregator/processMatchedVerticesAndSendMessages.cpp +impl/aggregator/sendBundledMessages.cpp +impl/aggregator/initialize.cpp +impl/aggregator/isAlreadyMatched.cpp +impl/aggregator/processMessages.cpp +impl/aggregator/parallelComputeCandidateMateB.cpp +) + foreach(file IN LISTS AMG_amgprec_source_C_files) list(APPEND amgprec_source_C_files ${CMAKE_CURRENT_LIST_DIR}/${file}) endforeach() + + +foreach(file IN LISTS AMG_amgprec_source_CPP_files) + list(APPEND amgprec_source_CPP_files ${CMAKE_CURRENT_LIST_DIR}/${file}) +endforeach()