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

Run tests in parallel on CI #49

Merged
merged 11 commits into from
Feb 22, 2024
62 changes: 25 additions & 37 deletions tests/CMakeLists.txt
pbartholomew08 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
set(TESTSRC
test_allocator.f90
omp/test_omp_tridiag.f90
omp/test_omp_transeq.f90
omp/test_omp_dist_transeq.f90
)
set(CUDATESTSRC
cuda/test_cuda_allocator.f90
cuda/test_cuda_reorder.f90
cuda/test_cuda_tridiag.f90
cuda/test_cuda_transeq.f90
)

if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "PGI" OR
${CMAKE_Fortran_COMPILER_ID} STREQUAL "NVHPC")
foreach(testfile IN LISTS CUDATESTSRC)
get_filename_component(test_name ${testfile} NAME_WE)

add_executable(${test_name} ${testfile})
target_compile_options(${test_name} PRIVATE "-cuda")
target_compile_options(${test_name} PRIVATE "-O3")
target_compile_options(${test_name} PRIVATE "-fast")
target_link_options(${test_name} INTERFACE "-cuda")
target_link_libraries(${test_name} PRIVATE x3d2)
set(CMAKE_CTEST_ARGUMENTS "--output-on-failure" CACHE STRING "comma separated list of arguments to pass to ctest")
set(CMAKE_CTEST_NPROCS "4" CACHE STRING "number of process used in tests")

add_test(NAME ${test_name} COMMAND sh -c "mpirun -np 1 ${test_name}")
endforeach()
endif()

foreach(testfile IN LISTS TESTSRC)
function(define_test testfile np backend)
get_filename_component(test_name ${testfile} NAME_WE)

add_executable(${test_name} ${testfile})

target_compile_options(${test_name} PRIVATE "-O3")

if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
target_compile_options(${test_name} PRIVATE "-ffast-math")
if(${backend} STREQUAL cuda)
target_compile_options(${test_name} PRIVATE "-cuda")
target_link_options(${test_name} INTERFACE "-cuda")
else()
find_package(OpenMP REQUIRED)
target_link_libraries(${test_name} PRIVATE OpenMP::OpenMP_Fortran)
endif()

target_link_libraries(${test_name} PRIVATE x3d2)

find_package(OpenMP REQUIRED)
target_link_libraries(${test_name} PRIVATE OpenMP::OpenMP_Fortran)
add_test(NAME ${test_name} COMMAND sh -c "mpirun --oversubscribe -np ${np} ${test_name}")

endfunction()

define_test(test_allocator.f90 1 omp)
define_test(omp/test_omp_tridiag.f90 ${CMAKE_CTEST_NPROCS} omp)
define_test(omp/test_omp_transeq.f90 ${CMAKE_CTEST_NPROCS} omp)
define_test(omp/test_omp_dist_transeq.f90 ${CMAKE_CTEST_NPROCS} omp)

if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "PGI" OR
${CMAKE_Fortran_COMPILER_ID} STREQUAL "NVHPC")
define_test(cuda/test_cuda_allocator.f90 1 cuda)
define_test(cuda/test_cuda_reorder.f90 1 cuda)
define_test(cuda/test_cuda_tridiag.f90 ${CMAKE_CTEST_NPROCS} cuda)
define_test(cuda/test_cuda_transeq.f90 ${CMAKE_CTEST_NPROCS} cuda)
endif()

add_test(NAME ${test_name} COMMAND sh -c "mpirun -np 1 ${test_name}")
endforeach()
Loading