From: Matthias Maier Date: Tue, 15 Feb 2022 12:39:10 +0000 (-0600) Subject: CMake: Allow to define multiple threads= variant tests X-Git-Tag: v9.4.0-rc1~475^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e91c15c81ac663b1660020cce45a0e258b2eaf0c;p=dealii.git CMake: Allow to define multiple threads= variant tests This change allow to define multiple test flavors with threads= similarly to how we handle mpirun=. For example, category/test.cc category/test.threads=2.output category/test.threads=4.output will now create one top level target to compile test.cc and define two tests "category/test.threads=2.(release|debug)" and "category/test.threads=4.(release|debug)" that execute the test program with a threadpool size set to 2 and 4, respectively. --- diff --git a/cmake/macros/macro_deal_ii_add_test.cmake b/cmake/macros/macro_deal_ii_add_test.cmake index d64df74c94..b766fe3929 100644 --- a/cmake/macros/macro_deal_ii_add_test.cmake +++ b/cmake/macros/macro_deal_ii_add_test.cmake @@ -335,26 +335,37 @@ FUNCTION(DEAL_II_ADD_TEST _category _test_name _comparison_file) # # Set up a bunch of variables describing this particular test: # - - # If _n_cpu is equal to "0", a normal, sequential test will be run, - # otherwise run the test with mpirun: - IF("${_n_cpu}" STREQUAL "0") - + # If _n_cpu or _n_threads are larger than zero we have to accomodate + # the fact that multiple output files specifying a different mpirun or + # threads count are present. In order to accomodate this we create a + # runtime subdirectory "mpirun_M-threads_N" to the test. + # + # Note that we could do this unconditionally for every test but for + # aesthetic reasons chose to not create the directory for + # "mpirun_0-threads_0". + # + IF("${_n_cpu}" STREQUAL "0" AND "${_n_threads}" STREQUAL "0") SET(_test_target ${_category}.${_test_name}.${_build_lowercase}.test) # diff target name SET(_test_full ${_category}/${_test_name}.${_build_lowercase}) # full test name SET(_test_directory ${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.${_build_lowercase}) # directory to run the test in ELSE() + SET(_test_target ${_category}.${_test_name}.mpirun${_n_cpu}.threads${_n_threads}.${_build_lowercase}.test) # diff target name + SET(_test_full ${_category}/${_test_name}.mpirun=${_n_cpu}.threads=${_n_threads}.${_build_lowercase}) # full test name + SET(_test_directory ${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.${_build_lowercase}/mpirun_${_n_cpu}-threads_${_n_threads}) # directory to run the test in + ENDIF() - SET(_test_target ${_category}.${_test_name}.mpirun${_n_cpu}.${_build_lowercase}.test) # diff target name - SET(_test_full ${_category}/${_test_name}.mpirun=${_n_cpu}.${_build_lowercase}) # full test name - SET(_test_directory ${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.${_build_lowercase}/mpirun=${_n_cpu}) # directory to run the test in + # + # Test variants with ".mpirun=[...]." have to be executed via mpirun + # (or whatever ${DEAL_II_MPIEXEC} is set to). + # + IF(NOT "${_n_cpu}" STREQUAL "0") SET(_run_args "${DEAL_II_MPIEXEC}" ${DEAL_II_MPIEXEC_NUMPROC_FLAG} ${_n_cpu} ${DEAL_II_MPIEXEC_PREFLAGS} ${_run_args} - "${DEAL_II_MPIEXEC_POSTFLAGS}" + ${DEAL_II_MPIEXEC_POSTFLAGS} ) ENDIF() @@ -377,7 +388,6 @@ FUNCTION(DEAL_II_ADD_TEST _category _test_name _comparison_file) COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${_target_short}/interrupt_guard.cc ) - ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL ${_generated_files} ${_source_file} @@ -495,12 +505,11 @@ FUNCTION(DEAL_II_ADD_TEST _category _test_name _comparison_file) SET_TESTS_PROPERTIES(${_test_full} PROPERTIES PROCESSORS ${_slots}) ENDIF() - IF(NOT "${_n_cpu}" STREQUAL "0") + IF(NOT "${_n_cpu}${_n_threads}" STREQUAL "00") # - # We have to be careful not to run different mpirun settings for the - # same executable in parallel because this triggers a race condition - # when compiling the not yet existent executable that is shared - # between the different tests. + # Running multiple variants in parallel triggers a race condition + # where the same (not yet existent) executable is built + # concurrently leading to undefined outcomes. # # Luckily CMake has a mechanism to force a test to be run after # another has finished (and both are scheduled):