diff --git a/cmake/bashrc b/cmake/bashrc index e905df58..50c62d8b 100644 --- a/cmake/bashrc +++ b/cmake/bashrc @@ -19,7 +19,7 @@ export pFlow_SRC_DIR="$pFlow_PROJECT_DIR/src" export Kokkos_DIR="$kokkosDir" -export Zoltan_DIR="$projectDir/Zoltan" +#export Zoltan_DIR="$projectDir/Zoltan" # Cleanup variables (done as final statement for a clean exit code) unset projectDir diff --git a/cmake/zoltanInstallCheck.cmake b/cmake/zoltanInstallCheck.cmake new file mode 100644 index 00000000..d0e6d8db --- /dev/null +++ b/cmake/zoltanInstallCheck.cmake @@ -0,0 +1,44 @@ +# Macro to check for Zoltan installation and build it if needed +# Usage: zoltan_find_or_build(ZOLTAN_DIR) +# Returns: ZOLTAN_INCLUDE_DIR, ZOLTAN_LIBRARY + +macro(zoltan_find_or_build ZOLTAN_DIR) + # Set the Zoltan directory + set(ZOLTAN_PREFIX "${ZOLTAN_DIR}" CACHE STRING "Zoltan install directory") + message(STATUS "Zoltan install directory is ${ZOLTAN_PREFIX}") + + # Check if the Zoltan library is already built + find_path(ZOLTAN_INCLUDE_DIR zoltan.h PATHS "${ZOLTAN_PREFIX}/include") + message(STATUS "Zoltan include path: ${ZOLTAN_INCLUDE_DIR}") + + find_library(ZOLTAN_LIBRARY zoltan PATHS "${ZOLTAN_PREFIX}/lib") + message(STATUS "Zoltan lib path: ${ZOLTAN_LIBRARY}") + + # Check if Zoltan library exists, if not compile it using buildlib script + if(NOT ZOLTAN_LIBRARY) + message(STATUS "Zoltan library not found. Compiling from source using buildlib script...") + + # Execute the buildlib bash script + execute_process( + COMMAND bash ${ZOLTAN_PREFIX}/buildlib + WORKING_DIRECTORY ${ZOLTAN_PREFIX} + RESULT_VARIABLE ZOLTAN_BUILD_RESULT + OUTPUT_VARIABLE ZOLTAN_BUILD_OUTPUT + ERROR_VARIABLE ZOLTAN_BUILD_ERROR + ) + + if(NOT ZOLTAN_BUILD_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to build Zoltan library using buildlib script. Error: ${ZOLTAN_BUILD_ERROR}") + endif() + + # Try to find the library again after building + find_library(ZOLTAN_LIBRARY zoltan PATHS "${ZOLTAN_PREFIX}/lib" NO_DEFAULT_PATH) + find_path(ZOLTAN_INCLUDE_DIR zoltan.h PATHS "${ZOLTAN_PREFIX}/include" NO_DEFAULT_PATH) + + if(NOT ZOLTAN_LIBRARY) + message(FATAL_ERROR "Failed to locate Zoltan library after building") + endif() + + message(STATUS "Successfully built Zoltan library at ${ZOLTAN_LIBRARY}") + endif() +endmacro() \ No newline at end of file diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index db66642e..5af3b7dd 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -1,4 +1,3 @@ - list(APPEND SourceFiles types/basicTypes/bTypesFunctions.cpp types/basicTypes/Logical.cpp @@ -119,35 +118,27 @@ set(link_libs) set(link_libs Kokkos::kokkos tbb) - +# for MPI parallelization if(pFlow_Build_MPI) - set(Zoltan_Install_DIR) - if(DEFINED ENV{Zoltan_DIR}) - set(Zoltan_Install_DIR $ENV{Zoltan_DIR}) - else() - set(Zoltan_Install_DIR $ENV{HOME}/PhasicFlow/Zoltan) - endif() - message(STATUS "Zoltan install directory is ${Zoltan_Install_DIR}") - - set(ZOLTAN_PREFIX "${Zoltan_Install_DIR}" CACHE STRING "Zoltan install directory") - - find_path(ZOLTAN_INCLUDE_DIR zoltan.h PATHS "${ZOLTAN_PREFIX}/include") - - message(STATUS "Zoltan include path: ${ZOLTAN_INCLUDE_DIR}") - - find_library(ZOLTAN_LIBRARY zoltan PATHS "${ZOLTAN_PREFIX}/lib") - message(STATUS "Zoltan lib path: ${ZOLTAN_LIBRARY}") + # Include the Zoltan installation check macro + include(${CMAKE_SOURCE_DIR}/cmake/zoltanInstallCheck.cmake) + + # set the Zoltan Directory and check/build if needed + set(Zoltan_Install_DIR ${CMAKE_SOURCE_DIR}/thirdParty/Zoltan) + + # Call the macro to find or build Zoltan + zoltan_find_or_build(${Zoltan_Install_DIR}) list(APPEND SourceFiles - MPIParallelization/domain/partitioning/partitioning.cpp - MPIParallelization/domain/partitioning/rcb1DPartitioning.cpp - MPIParallelization/domain/MPISimulationDomain.cpp - MPIParallelization/dataIOMPI/dataIOMPIs.cpp - MPIParallelization/MPI/procCommunication.cpp - MPIParallelization/MPI/scatteredMasterDistributeChar.cpp - MPIParallelization/pointStructure/boundaries/boundaryProcessor.cpp - MPIParallelization/pointField/processorBoundaryFields.cpp + MPIParallelization/domain/partitioning/partitioning.cpp + MPIParallelization/domain/partitioning/rcb1DPartitioning.cpp + MPIParallelization/domain/MPISimulationDomain.cpp + MPIParallelization/dataIOMPI/dataIOMPIs.cpp + MPIParallelization/MPI/procCommunication.cpp + MPIParallelization/MPI/scatteredMasterDistributeChar.cpp + MPIParallelization/pointStructure/boundaries/boundaryProcessor.cpp + MPIParallelization/pointField/processorBoundaryFields.cpp ) list(APPEND link_libs MPI::MPI_CXX ${ZOLTAN_LIBRARY} -lm ) @@ -155,8 +146,10 @@ if(pFlow_Build_MPI) target_include_directories(phasicFlow PUBLIC ./globals ${ZOLTAN_INCLUDE_DIR}) else() - pFlow_add_library_install(phasicFlow SourceFiles link_libs) + +pFlow_add_library_install(phasicFlow SourceFiles link_libs) target_include_directories(phasicFlow PUBLIC ./globals) + endif()