1- cmake_minimum_required (VERSION 3.16.3 )
2-
3- project (GMGPolar VERSION 1.0.0)
1+ cmake_minimum_required (VERSION 3.12 )
2+ project (GMGPolar VERSION 2.0.0 LANGUAGES CXX )
43
54option (GMGPOLAR_BUILD_TESTS "Build GMGPolar unit tests." ON )
6- option (GMGPOLAR_USE_MUMPS "Use MUMPS to compute matrix factorizations." OFF )
75option (GMGPOLAR_USE_LIKWID "Use LIKWID to measure code (regions)." OFF )
6+ option (GMGPOLAR_USE_MUMPS "Use MUMPS to solve linear systems." OFF )
87
8+ set (CMAKE_CXX_STANDARD 20)
9+ set (CMAKE_CXX_STANDARD_REQUIRED True )
910
10- set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" ${CMAKE_MODULE_PATH} )
11- set (CMAKE_POSITION_INDEPENDENT_CODE ON )
12-
13- set (CMAKE_CXX_FLAGS "" )
14- set (CMAKE_LINKER_FLAGS "" )
15-
16- add_subdirectory (src )
17-
18- # code coverage analysis
19- # Note: this only works under linux and with make
20- # Ninja creates different directory names which do not work together with this scrupt
21- # as STREQUAL is case-sensitive https://github.com/TriBITSPub/TriBITS/issues/131, also allow DEBUG as accepted input
22- option (GMGPOLAR_TEST_COVERAGE "Enable GCov coverage analysis (adds a 'coverage' target)" OFF )
23-
24- if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
25- if (GMGPOLAR_TEST_COVERAGE)
26- message (STATUS "Coverage enabled" )
27- include (CodeCoverage )
28- append_coverage_compiler_flags ()
29- setup_target_for_coverage_lcov (
30- NAME coverage
31- EXECUTABLE tests/gmgpolar_tests
32- EXCLUDE "${CMAKE_SOURCE_DIR} /tests*" "${CMAKE_SOURCE_DIR} /src/test_cases*" "${CMAKE_BINARY_DIR} /*" "/usr*"
33- )
34- endif ()
11+ if (NOT CMAKE_BUILD_TYPE )
12+ set (CMAKE_BUILD_TYPE Release)
3513endif ()
3614
37-
38- add_library (GMGPolar ${SOURCES_SRC} )
39-
40- add_executable (gmgpolar_simulation ./src/main.cpp )
41-
42- configure_file (${CMAKE_SOURCE_DIR} /include/config_internal.h.in ${CMAKE_SOURCE_DIR} /include/config_internal.h )
43-
44- target_include_directories (gmgpolar_simulation PRIVATE ${CMAKE_SOURCE_DIR} /include ${CMAKE_SOURCE_DIR} /include/test_cases )
45- target_include_directories (GMGPolar PRIVATE ${CMAKE_SOURCE_DIR} /include ${CMAKE_SOURCE_DIR} /include/test_cases )
46-
15+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -Wno-unused" )
16+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -mtune=generic" )
17+
18+ # # Mumps: Sparse Matrix Solver
19+ # set(MUMPS_PREFIX_PATH "~/spack/opt/spack/linux-ubuntu20.04-icelake/gcc-9.4.0/mumps-5.6.2-m4xrhc4mshzrxmgptzbpult3nbf6qrzk")
20+ # include_directories(${MUMPS_PREFIX_PATH}/include)
21+ # link_directories(${MUMPS_PREFIX_PATH}/lib)
22+
23+ # # Metis: Matrix reordering for Mumps
24+ # set(METIS_PREFIX_PATH "~/spack/opt/spack/linux-ubuntu20.04-icelake/gcc-9.4.0/metis-5.1.0-bgoncx22w55soviybggl5ydjakvkm34v")
25+ # include_directories(${METIS_PREFIX_PATH}/include)
26+ # link_directories(${METIS_PREFIX_PATH}/lib)
27+
28+ # # Likwid: Performance monitoring
29+ # set(LIKWID_PREFIX_PATH "~/spack/opt/spack/linux-ubuntu20.04-icelake/gcc-9.4.0/likwid-5.3.0-6mvx2snsqnamuyhaqspd6gxkfuaso36g")
30+ # include_directories(${LIKWID_PREFIX_PATH}/include)
31+ # link_directories(${LIKWID_PREFIX_PATH}/lib)
32+
33+ # Include directories for the project
34+ include_directories (include )
35+
36+ # 1. Create a library target for the PolarGrid module
37+ file (GLOB_RECURSE POLAR_GRID_SOURCES "src/PolarGrid/*.cpp" )
38+ add_library (PolarGrid STATIC ${POLAR_GRID_SOURCES} )
39+ target_include_directories (PolarGrid PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /src/PolarGrid )
40+
41+ # 2. Create a library target for the InputFunctions module
42+ file (GLOB_RECURSE INPUT_FUNCTIONS_SOURCES
43+ "src/InputFunctions/DensityProfileCoefficients/*.cpp"
44+ "src/InputFunctions/DomainGeometry/*.cpp"
45+ "src/InputFunctions/ExactSolution/*.cpp"
46+ "src/InputFunctions/BoundaryConditions/*.cpp"
47+ "src/InputFunctions/SourceTerms/*.cpp"
48+ )
49+ add_library (InputFunctions STATIC ${INPUT_FUNCTIONS_SOURCES} )
50+ target_include_directories (InputFunctions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /src/InputFunctions )
51+
52+ # 3. Collect all the common source files for GMGPolar into a library
53+ file (GLOB_RECURSE GMG_POLAR_SOURCES "src/GMGPolar/*.cpp" )
54+ file (GLOB_RECURSE MULTIGRID_METHODS_SOURCES "src/GMGPolar/MultigridMethods/*.cpp" )
55+ file (GLOB_RECURSE LEVEL_SOURCES "src/Level/*.cpp" )
56+ file (GLOB_RECURSE STENCIL_SOURCES "src/Stencil/*.cpp" )
57+ file (GLOB_RECURSE INTERPOLATION_SOURCES "src/Interpolation/*.cpp" )
58+ file (GLOB_RECURSE DIRECT_SOLVER_SOURCES "src/DirectSolver/*.cpp" "src/DirectSolverGive/*.cpp" "src/DirectSolverTake/*.cpp" "src/DirectSolverGiveCustomLU/*.cpp" "src/DirectSolverTakeCustomLU/*.cpp" )
59+ file (GLOB_RECURSE RESIDUAL_SOURCES "src/Residual/*.cpp" "src/Residual/ResidualGive/*.cpp" "src/Residual/ResidualTake/*.cpp" )
60+ file (GLOB_RECURSE SMOOTHER_SOURCES "src/Smoother/*.cpp" "src/SmootherGive/*.cpp" "src/SmootherTake/*.cpp" )
61+ file (GLOB_RECURSE EXTRAPOLATED_SMOOTHER_SOURCES "src/ExtrapolatedSmoother/*.cpp" "src/ExtrapolatedSmoother/ExtrapolatedSmootherGive/*.cpp" "src/ExtrapolatedSmoother/ExtrapolatedSmootherTake/*.cpp" )
62+
63+ # 4. Create the GMGPolarLib library and link PolarGrid and InputFunctions
64+ add_library (GMGPolarLib STATIC
65+ ${GMG_POLAR_SOURCES}
66+ ${MULTIGRID_METHODS_SOURCES}
67+ ${LEVEL_SOURCES}
68+ ${STENCIL_SOURCES}
69+ ${INTERPOLATION_SOURCES}
70+ ${DIRECT_SOLVER_SOURCES}
71+ ${RESIDUAL_SOURCES}
72+ ${SMOOTHER_SOURCES}
73+ ${EXTRAPOLATED_SMOOTHER_SOURCES}
74+ )
75+ # Link PolarGrid and InputFunctions to GMGPolarLib
76+ target_link_libraries (GMGPolarLib PUBLIC PolarGrid InputFunctions )
77+
78+ # Link Likwid to GMGPolarLib
4779if (GMGPOLAR_USE_LIKWID)
48-
49- find_package (LIKWID REQUIRED )
50-
51- target_include_directories (GMGPolar PUBLIC ${LIKWID_INCLUDE_DIRS} )
52- target_link_libraries (GMGPolar PUBLIC ${LIKWID_LIBRARIES} )
53- target_compile_definitions (GMGPolar PUBLIC "-DLIKWID_PERFMON" )
54-
80+ target_link_libraries (GMGPolarLib PUBLIC likwid )
81+ target_compile_definitions (GMGPolarLib PUBLIC "-DLIKWID_PERFMON" )
82+ add_compile_definitions (GMGPOLAR_USE_LIKWID )
5583endif ()
5684
57-
58-
85+ # Link Mumps to GMGPolarLib
5986if (GMGPOLAR_USE_MUMPS)
60-
61- set (INC_DIRS
62- /home/kueh_mj/.spack/rev.23.05/install/linux -rocky8-zen2/gcc-10.4.0/mumps-5.4.1-fftqkl/include
63- /sw/rev/23.05/linux -rocky8-zen2/gcc-10.4.0/metis-5.1.0-akhgsf/include
64- )
65-
66- set (LIB_DIRS
67- /home/kueh_mj/.spack/rev.23.05/install/linux -rocky8-zen2/gcc-10.4.0/mumps-5.4.1-fftqkl/lib
68- /sw/rev/23.05/linux -rocky8-zen2/gcc-10.4.0/metis-5.1.0-akhgsf/lib
69- )
70-
71- include_directories (
72- ${INC_DIRS}
73- )
74-
75- target_link_directories (
76- GMGPolar
77- PUBLIC
78- ${LIB_DIRS}
79- )
80-
81- set (LIBS
82- mpiseq
83- dmumps
87+ set (MUMPS_LIBRARIES
8488 mumps_common
89+ smumps
90+ dmumps
91+ mpiseq
8592 metis
8693 )
87-
88- target_link_libraries (
89- GMGPolar
90- PUBLIC
91- ${LIBS}
92- )
94+ target_link_libraries (GMGPolarLib PUBLIC ${MUMPS_LIBRARIES} )
95+ add_compile_definitions (GMGPOLAR_USE_MUMPS )
9396endif ()
9497
95-
96- find_package (OpenMP )
97-
98- #currently works on GNU compiler
99- if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" ) AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7))
100-
101- string (APPEND CMAKE_CXX_FLAGS " -O2 -Wall -MMD -MP -Wwrite-strings" )
102- string (APPEND CMAKE_LINKER_FLAGS " -O2 -Wall -MMD -MP -Wwrite-strings" )
103-
104- if (OPENMP_FOUND)
105- string (APPEND CMAKE_CXX_FLAGS " -fopenmp" )
106- string (APPEND CMAKE_LINKER_FLAGS " -fopenmp" )
107-
108- else ()
109- message (FATAL_ERROR "OpenMP needed" )
110- endif ()
111- else ()
112- message (FATAL_ERROR "Please use GNU compiler or change CMakeLists manually" )
98+ # Add OpenMP flags if available and link to GMGPolarLib
99+ find_package (OpenMP REQUIRED )
100+ if (OpenMP_CXX_FOUND)
101+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} " )
102+ target_link_libraries (GMGPolarLib PUBLIC OpenMP::OpenMP_CXX )
113103endif ()
114104
105+ # 5. Add the main executable target (gmgpolar)
106+ set (MAIN_SOURCE "src/main.cpp" )
107+ add_executable (gmgpolar ${MAIN_SOURCE} )
108+
109+ # 6. Add another executable target (convergence_order)
110+ set (CONVERGENCE_ORDER_SOURCE "src/convergence_order.cpp" )
111+ add_executable (convergence_order ${CONVERGENCE_ORDER_SOURCE} )
115112
116- target_link_libraries (gmgpolar_simulation PRIVATE GMGPolar )
113+ set (WEAK_SCALING_SOURCE "src/weak_scaling.cpp" )
114+ add_executable (weak_scaling ${WEAK_SCALING_SOURCE} )
117115
116+ set (STRONG_SCALING_SOURCE "src/strong_scaling.cpp" )
117+ add_executable (strong_scaling ${STRONG_SCALING_SOURCE} )
118118
119- include (thirdparty/CMakeLists.txt )
120- add_subdirectory (tests )
119+ # 7. Link GMGPolarLib (which now includes PolarGrid and InputFunctions) to both executables
120+ target_link_libraries (gmgpolar PRIVATE GMGPolarLib )
121+ target_link_libraries (convergence_order PRIVATE GMGPolarLib )
122+ target_link_libraries (weak_scaling PRIVATE GMGPolarLib )
123+ target_link_libraries (strong_scaling PRIVATE GMGPolarLib )
121124
125+ # 9. Enable testing and include other directories
126+ if (GMGPOLAR_BUILD_TESTS)
127+ enable_testing ()
128+ add_subdirectory (third-party )
129+ add_subdirectory (tests )
130+ endif ()
0 commit comments