Closed BenjaminTJohnson closed 3 years ago
Hi. Yes, indeed you need to use the ENVIRONMENT keyword of the ecbuild_add_test function.
ENVIRONMENT OMP_NUM_THREADS=$ENV{OMP_NUM_THREADS}
or
ENVIRONMENT OMP_NUM_THREADS=${cmake_variable_with_num_threads}
@tlmquintino Thanks, much appreciated.
@BenjaminTJohnson , I would like to add to the response.
ecbuild_add_test()
explicitly sets OMP_NUM_THREADS=1 in the environment by default. This is to be independent of the user environment or platform environment.
If you want something different, you need to modify the argument "OMP". If you like to test with e.g. 4 OpenMP threads:
ecbuild_add_test( ... OMP 4 )
This will then set OMP_NUM_THREADS=4
in the environment. This will then always be deterministic for your tests.
If you use
ecbuild_add_test( ... OMP $ENV{OMP_NUM_THREADS} )
then you pick up the number of OMP threads at configuration time, not run-time. The problem is also that you are not deterministic anymore.
If you want to run the test executable with a custom OMP_NUM_THREADS, e.g. in development, I suggest to run the test program manually without ctest
.
You can also take following approach if you want to test the same program with different OMP_NUM_THREADS:
ecbuild_add_executable( TARGET mytest_program NOINSTALL ... ) # executable will be in the test directory, not bin
ecbuild_add_test( TARGET mytest_omp2 COMMAND mytest_program OMP 2 )
ecbuild_add_test( TARGET mytest_omp4 COMMAND mytest_program OMP 4 )
When running
ctest
it appears that the tests added usingecbuild_add_test
do not automatically grab the OMP_NUM_THREADS from the environment (e.g., bash).(1) Is there a way to pick up the environment variable at runtime? (2) If not, is setting
OMP
keyword inside ofecbuild_add_test
and using $ENV{OMP_NUM_THREADS} the recommended approach, or do I need to (also?) use theENVIRONMENT
keyword?Thanks for any advice / commentary.