From 1cfd2131bcd04bdc06991ed729d7ee0cf2fd16ab Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 9 Feb 2022 03:58:11 -0600 Subject: [PATCH] CMake: support "threads=N" and "threads=max" statements for tests --- cmake/macros/macro_deal_ii_add_test.cmake | 40 +++++++++++++++++-- cmake/macros/macro_deal_ii_pickup_tests.cmake | 5 ++- cmake/scripts/run_test.sh | 16 +++++++- doc/developers/testsuite.html | 13 ++++++ doc/users/testsuite.html | 9 +++-- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/cmake/macros/macro_deal_ii_add_test.cmake b/cmake/macros/macro_deal_ii_add_test.cmake index cb8c5537cc..39d920fb21 100644 --- a/cmake/macros/macro_deal_ii_add_test.cmake +++ b/cmake/macros/macro_deal_ii_add_test.cmake @@ -82,7 +82,8 @@ # - Specifies the maximal number of worker threads that can should be # used by the threading backend. Note that individual tests might # exceed this limit by calling MultithreadInfo::set_thread_limit(), or -# by manually creating additional threads. Defaults to 3. +# by manually creating additional threads. The special value 0 +# enforces no limit. Defaults to 0. # # Usage: # DEAL_II_ADD_TEST(category test_name comparison_file) @@ -121,7 +122,7 @@ FUNCTION(DEAL_II_ADD_TEST _category _test_name _comparison_file) ENDIF() # - # If we encountered the special string "mpirun=max" set the number of MPI + # If we encounter the special string "mpirun=max" set the number of MPI # ranks used for the test to the maximum number of allowed ranks. If no # limit has been specified, i.e., TEST_MPI_RANK_LIMIT is 0, skip defining # the test. @@ -141,6 +142,39 @@ FUNCTION(DEAL_II_ADD_TEST _category _test_name _comparison_file) RETURN() ENDIF() + # + # Determine whether the test declaration specifies a thread pool size via + # threads=N: + # + STRING(REGEX MATCH "threads=([0-9]+|max)" _n_threads ${_file}) + IF("${_n_threads}" STREQUAL "") + SET(_n_threads 0) # 0 indicates that the default thread pool size + # should be used (currently set to 3 in tests.h) + ELSE() + STRING(REGEX REPLACE "^threads=([0-9]+|max)$" "\\1" _n_threads ${_n_threads}) + ENDIF() + + # + # If we encounter the special string "threads=max" set the number of + # threads of the threading pool to the maximum number of allowed threads. + # If no limit has been specified, i.e., TEST_THREAD_LIMIT is 0, skip + # defining the test. + # + IF("${_n_threads}" STREQUAL "max") + IF(TEST_THREAD_LIMIT EQUAL 0) + RETURN() + ENDIF() + SET(_n_threads "${TEST_THREAD_LIMIT}") + ENDIF() + + # + # If the number of threads specified for the test via .threads=N. exceeds + # the limit ${TEST_THREAD_LIMIT}, skip defining the test + # + IF(TEST_THREAD_LIMIT GREATER 0 AND _n_threads GREATER TEST_THREAD_LIMIT) + RETURN() + ENDIF() + # # Determine the expected build stage of this test: # @@ -342,7 +376,7 @@ FUNCTION(DEAL_II_ADD_TEST _category _test_name _comparison_file) # ADD_CUSTOM_COMMAND(OUTPUT ${_test_directory}/output - COMMAND TEST_THREAD_LIMIT=${TEST_THREAD_LIMIT} + COMMAND TEST_N_THREADS=${_n_threads} sh ${DEAL_II_PATH}/${DEAL_II_SHARE_RELDIR}/scripts/run_test.sh run "${_test_full}" ${_run_args} COMMAND ${PERL_EXECUTABLE} diff --git a/cmake/macros/macro_deal_ii_pickup_tests.cmake b/cmake/macros/macro_deal_ii_pickup_tests.cmake index 6fefd66af3..8651614cea 100644 --- a/cmake/macros/macro_deal_ii_pickup_tests.cmake +++ b/cmake/macros/macro_deal_ii_pickup_tests.cmake @@ -45,7 +45,8 @@ # - Specifies the maximal number of worker threads that can should be # used by the threading backend. Note that individual tests might # exceed this limit by calling MultithreadInfo::set_thread_limit(), -# or by manually creating additional threads. Defaults to 3. +# or by manually creating additional threads. The special value 0 +# enforces no limit. Defaults to 0. # # TEST_PICKUP_REGEX # - A regular expression to select only a subset of tests during setup. @@ -190,7 +191,7 @@ MACRO(DEAL_II_PICKUP_TESTS) SET_IF_EMPTY(TEST_MPI_RANK_LIMIT 0) SET_IF_EMPTY(TEST_THREAD_LIMIT "$ENV{TEST_THREAD_LIMIT}") - SET_IF_EMPTY(TEST_THREAD_LIMIT 3) + SET_IF_EMPTY(TEST_THREAD_LIMIT 0) # # ... and finally pick up tests: diff --git a/cmake/scripts/run_test.sh b/cmake/scripts/run_test.sh index f941daa5fe..1fe38f66e5 100644 --- a/cmake/scripts/run_test.sh +++ b/cmake/scripts/run_test.sh @@ -43,8 +43,20 @@ case $STAGE in # failing_output ## - # Limit the deal.II thread pool to TEST_THREAD_LIMIT threads. - export TEST_N_THREADS="${TEST_THREAD_LIMIT}" + # + # If TEST_N_THREADS is not equal to zero then: + # - Export the environment variable DEAL_II_NUM_THREADS set to + # $TEST_N_THREADS. This will enforce an upper bound of + # DEAL_II_NUM_THREADS during thread initialization of the threading + # pool in deal.II. + # - Export TEST_N_THREADS which is internally used in the deal.II + # testsuite to explicitly set the number of threads in the header + # file tests.h. + # + if [ "${TEST_N_THREADS+0}" -ne 0 ]; then + export DEAL_II_NUM_THREADS="${TEST_N_THREADS}" + export TEST_N_THREADS + fi # Limit the OpenMP pool to two threads. export OMP_NUM_THREADS="2" diff --git a/doc/developers/testsuite.html b/doc/developers/testsuite.html index 96b0724dba..ae5fb39dac 100644 --- a/doc/developers/testsuite.html +++ b/doc/developers/testsuite.html @@ -110,6 +110,19 @@ TEST_TIME_LIMIT - The time limit (in seconds) a single test is allowed to take. Defaults to 180 seconds +TEST_MPI_RANK_LIMIT + - Specifies the maximal number of MPI ranks that can be used. If a + test variant configures a larger number of MPI ranks (via + .mpirun=N. in the output file) than this limit the test will be + dropped. The special value 0 enforces no limit. Defaults to 0. + +TEST_THREAD_LIMIT + - Specifies the maximal number of worker threads that can should be + used by the threading backend. Note that individual tests might + exceed this limit by calling MultithreadInfo::set_thread_limit(), or + by manually creating additional threads. The special value 0 + enforces no limit. Defaults to 0. + TEST_PICKUP_REGEX - A regular expression to select only a subset of tests during setup. An empty string is interpreted as a catchall (this is the default). diff --git a/doc/users/testsuite.html b/doc/users/testsuite.html index dca3c60c6e..dfbf6de5c0 100644 --- a/doc/users/testsuite.html +++ b/doc/users/testsuite.html @@ -322,10 +322,11 @@ TEST_MPI_RANK_LIMIT dropped. The special value 0 enforces no limit. Defaults to 0. TEST_THREAD_LIMIT - - Specifies the maximal number of worker threads that can should be used - by the threading backend. Note that individual tests might exceed this - limit by calling MultithreadInfo::set_thread_limit(), or by manually - creating additional threads. Defaults to 3. + - Specifies the maximal number of worker threads that can should be + used by the threading backend. Note that individual tests might + exceed this limit by calling MultithreadInfo::set_thread_limit(), or + by manually creating additional threads. The special value 0 + enforces no limit. Defaults to 0.
-- 2.39.5