Skip to content

Commit 5cdc236

Browse files
authored
Merge pull request #84 from henryleberre/master
Fix undefined
2 parents 95ac09d + b8c975f commit 5cdc236

File tree

2 files changed

+83
-74
lines changed

2 files changed

+83
-74
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ on:
1616
workflow_dispatch:
1717

1818
jobs:
19-
tests:
20-
name: Test Suite
19+
github:
20+
name: (GitHub) Test Suite
2121
strategy:
2222
matrix:
2323
include:
2424
- os: ubuntu-latest
2525
- os: macos-latest
2626
gcc: 11
27-
- os: self-hosted
28-
2927
runs-on: ${{ matrix.os }}
3028
steps:
3129
- name: Clone
@@ -46,9 +44,27 @@ jobs:
4644
- name: Setup
4745
if: matrix.os == 'ubuntu-latest'
4846
run: sudo apt install tar wget make cmake gcc g++ python3 python3-dev "openmpi-*" libopenmpi-dev
47+
48+
- name: Build
49+
run: /bin/bash mfc.sh build -j $(nproc)
50+
51+
- name: Test Suite
52+
run: /bin/bash mfc.sh test -j $(nproc)
53+
54+
self:
55+
name: (Self) Test Suite
56+
strategy:
57+
matrix:
58+
include:
59+
- os: self-hosted
60+
runs-on: ${{ matrix.os }}
61+
if: github.repository == 'MFlowCode/MFC'
62+
steps:
63+
- name: Clone
64+
uses: actions/checkout@v3
4965

5066
- name: Setup
51-
if: matrix.os == 'self-hosted'
67+
if:
5268
run: |
5369
module use /opt/nvidia/hpc_sdk/modulefiles/
5470
module load nvhpc/22.11

CMakeLists.txt

Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
148148
endif()
149149

150150
## === HANDLE_SOURCES
151+
# Gather F90 source files for a given target, including common/, and preprocessing .fpp -> .f90.
151152
# Outputs:
152153
# - <target>_SRCs: List of F90 source filepaths for src/[<target>,common]/ (including .fpp -> .f90)
153154
macro(HANDLE_SOURCES target)
@@ -188,66 +189,41 @@ macro(HANDLE_SOURCES target)
188189
endforeach()
189190
endmacro()
190191

191-
192192
HANDLE_SOURCES(pre_process)
193193
HANDLE_SOURCES(simulation)
194194
HANDLE_SOURCES(post_process)
195195

196-
# === === src/pre_process
197-
if (MFC_PRE_PROCESS)
198-
add_executable(pre_process ${pre_process_SRCs})
199-
200-
if (MFC_MPI)
201-
find_package(MPI COMPONENTS Fortran REQUIRED)
202-
203-
target_compile_definitions(pre_process PRIVATE MFC_MPI)
204-
target_link_libraries (pre_process PRIVATE MPI::MPI_Fortran)
205-
endif()
206-
207-
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
208-
target_compile_options(pre_process PRIVATE -h noacc -x acc)
209-
endif()
210-
211-
target_compile_definitions(pre_process PRIVATE MFC_PRE_PROCESS)
212196

213-
install(TARGETS pre_process RUNTIME DESTINATION bin)
214-
endif()
197+
## === MFC_SETUP_TARGET
198+
# Setup a target with the following options:
199+
# - TARGET: Target name
200+
# - SOURCES: List of source files
201+
# - OpenACC: Can be compiled with OpenACC
202+
# - MPI: Can be compiled with MPI
203+
function(MFC_SETUP_TARGET)
204+
cmake_parse_arguments(ARGS "OpenACC;MPI" "TARGET" "SOURCES" ${ARGN})
215205

206+
add_executable(${ARGS_TARGET} ${ARGS_SOURCES})
216207

217-
# === === src/simulation
218-
if (MFC_SIMULATION)
219-
add_executable(simulation ${simulation_SRCs})
220-
221-
if (MFC_MPI)
208+
if (MFC_MPI AND ARGS_MPI)
222209
find_package(MPI COMPONENTS Fortran REQUIRED)
223210

224-
target_compile_definitions(simulation PRIVATE MFC_MPI)
225-
target_link_libraries (simulation PRIVATE MPI::MPI_Fortran)
226-
endif()
227-
228-
# === === === FFTW
229-
if (MFC_OpenACC AND (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI"))
230-
find_package(CUDAToolkit REQUIRED)
231-
232-
target_link_libraries(simulation PRIVATE CUDA::cudart CUDA::cufft)
233-
else()
234-
find_package(FFTW REQUIRED)
235-
236-
target_link_libraries(simulation PRIVATE FFTW::FFTW)
211+
target_compile_definitions(${ARGS_TARGET} PRIVATE MFC_MPI)
212+
target_link_libraries (${ARGS_TARGET} PRIVATE MPI::MPI_Fortran)
237213
endif()
238214

239-
if (MFC_OpenACC)
215+
if (MFC_OpenACC AND ARGS_OpenACC)
240216
find_package(OpenACC)
241217

242218
# This should be equivalent to if (NOT OpenACC_FC_FOUND)
243219
if (NOT TARGET OpenACC::OpenACC_Fortran)
244220
message(FATAL_ERROR "OpenACC + Fortran is unsupported.")
245221
endif()
246222

247-
target_link_libraries(simulation PRIVATE OpenACC::OpenACC_Fortran)
223+
target_link_libraries(${ARGS_TARGET} PRIVATE OpenACC::OpenACC_Fortran)
248224

249225
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
250-
target_compile_options(simulation PRIVATE
226+
target_compile_options(${ARGS_TARGET} PRIVATE
251227
"-foffload=amdgcn-amdhsa='-march=gfx90a'"
252228
"-foffload-options=-lgfortran\ -lm"
253229
"-fno-exceptions")
@@ -259,62 +235,80 @@ if (MFC_SIMULATION)
259235
"built without support for it, disallowing the use of "
260236
"cu_tensor=T. This can result in degraded performance.")
261237
else()
262-
target_link_libraries (simulation PRIVATE cuTENSOR::cuTENSOR)
263-
target_compile_definitions(simulation PRIVATE MFC_cuTENSOR)
238+
target_link_libraries (${ARGS_TARGET} PRIVATE cuTENSOR::cuTENSOR)
239+
target_compile_definitions(${ARGS_TARGET} PRIVATE MFC_cuTENSOR)
264240
endif()
265241

266242
if (CMAKE_BUILD_TYPE STREQUAL "Release")
267-
target_compile_options(simulation
243+
target_compile_options(${ARGS_TARGET}
268244
PRIVATE -gpu=keep,ptxinfo,lineinfo
269245
)
270246
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
271-
target_compile_options(simulation
247+
target_compile_options(${ARGS_TARGET}
272248
PRIVATE -gpu=keep,ptxinfo,lineinfo,autocompare,debug
273249
)
274250
endif()
275251
endif()
276252
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
277-
target_compile_options(simulation PRIVATE -h noacc -x acc)
253+
target_compile_options(${ARGS_TARGET} PRIVATE -h noacc -x acc)
254+
endif()
255+
256+
string(TOUPPER "${ARGS_TARGET}" ARGS_TARGET_UPPER)
257+
258+
target_compile_definitions(${ARGS_TARGET} PRIVATE "MFC_${ARGS_TARGET_UPPER}")
259+
260+
install(TARGETS ${ARGS_TARGET} RUNTIME DESTINATION bin)
261+
endfunction()
262+
263+
264+
if (MFC_PRE_PROCESS)
265+
MFC_SETUP_TARGET(
266+
TARGET pre_process
267+
SOURCES "${pre_process_SRCs}"
268+
MPI
269+
)
270+
endif()
271+
272+
273+
if (MFC_SIMULATION)
274+
MFC_SETUP_TARGET(
275+
TARGET simulation
276+
SOURCES "${simulation_SRCs}"
277+
MPI OpenACC
278+
)
279+
280+
if (MFC_OpenACC AND (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI"))
281+
find_package(CUDAToolkit REQUIRED)
282+
283+
target_link_libraries(simulation PRIVATE CUDA::cudart CUDA::cufft)
284+
else()
285+
find_package(FFTW REQUIRED)
286+
287+
target_link_libraries(simulation PRIVATE FFTW::FFTW)
278288
endif()
279289

280290
if (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
281291
find_package(CUDAToolkit REQUIRED)
282292
target_link_libraries(simulation PRIVATE CUDA::nvToolsExt)
283293
endif()
284-
285-
target_compile_definitions(simulation PRIVATE MFC_SIMULATION)
286-
287-
install(TARGETS simulation RUNTIME DESTINATION bin)
288294
endif()
289295

290296

291-
# === === src/post_process
292297
if (MFC_POST_PROCESS)
293-
add_executable(post_process ${post_process_SRCs})
298+
MFC_SETUP_TARGET(
299+
TARGET post_process
300+
SOURCES "${post_process_SRCs}"
301+
MPI
302+
)
294303

295304
find_package(FFTW REQUIRED)
296305
find_package(SILO REQUIRED)
297306
find_package(HDF5 REQUIRED)
298307

299308
target_link_libraries(post_process PRIVATE SILO::SILO HDF5::HDF5 FFTW::FFTW)
300309

301-
if (MFC_MPI)
302-
find_package(MPI COMPONENTS Fortran REQUIRED)
303-
304-
target_compile_definitions(post_process PRIVATE MFC_MPI)
305-
target_link_libraries (post_process PRIVATE MPI::MPI_Fortran)
306-
endif()
307-
308-
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
309-
target_compile_options(post_process PRIVATE -h noacc -x acc)
310-
endif()
311-
312310
# -O0 is in response to https://github.com/MFlowCode/MFC-develop/issues/95
313-
target_compile_definitions(post_process PRIVATE MFC_POST_PROCESS)
314-
target_compile_options (post_process PRIVATE -O0)
315-
316-
317-
install(TARGETS post_process RUNTIME DESTINATION bin)
311+
target_compile_options(post_process PRIVATE -O0)
318312
endif()
319313

320314

@@ -345,7 +339,7 @@ macro(GEN_DOCS target name)
345339
add_custom_command(
346340
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/doxygen/${target}/html/index.html"
347341
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doxygen/${target}/Doxyfile"
348-
"${${target}_srcs}"
342+
"${${target}_SRCs}"
349343
COMMAND "${DOXYGEN_EXECUTABLE}"
350344
"Doxyfile"
351345
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/${target}"
@@ -404,4 +398,3 @@ if (MFC_DOCUMENTATION)
404398
# === === Generate Landing Page
405399
GEN_DOCS(documentation "MFC")
406400
endif()
407-

0 commit comments

Comments
 (0)