From: Timo Heister Date: Mon, 31 Aug 2015 13:25:11 +0000 (-0400) Subject: update affinity test and error message X-Git-Tag: v8.4.0-rc2~508^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a3ee78db381502a9e277805f5bd0e31e5884514;p=dealii.git update affinity test and error message Report DEAL_II_NUM_THREADS and don't error out if it is set to some value. This was the reason we removed it in 384d5c6. --- diff --git a/tests/quick_tests/affinity.cc b/tests/quick_tests/affinity.cc index 24bb167541..ad433a3d7b 100644 --- a/tests/quick_tests/affinity.cc +++ b/tests/quick_tests/affinity.cc @@ -13,8 +13,15 @@ // // --------------------------------------------------------------------- +/* + Test that OpenMP is not messing with thread affinity, which will stop TBB + from creating threads. + */ + + #include #include +#include #include #if defined(__linux__) @@ -50,6 +57,26 @@ bool getaffinity(unsigned int &bits_set,unsigned int &mask) return true; } +int get_num_thread_env() +{ + const char *penv = getenv ("DEAL_II_NUM_THREADS"); + if (penv!=NULL) + { + int max_threads_env = -1; + try + { + max_threads_env = dealii::Utilities::string_to_int(std::string(penv)); + } + catch (...) + { + return -1; + } + return max_threads_env; + } + + return -1; +} + int main () { @@ -62,14 +89,20 @@ int main () unsigned int nprocs = dealii::MultithreadInfo::n_cores(); unsigned int tbbprocs = dealii::MultithreadInfo::n_threads(); - printf("aff_ncpus=%d, mask=%08X, nprocs=%d, tbb_threads=%d\n", - bits_set, mask, nprocs, tbbprocs ); + int env = get_num_thread_env(); + printf("aff_ncpus=%d, mask=%08X, nprocs=%d, tbb_threads=%d, DEAL_II_NUM_THREADS=%d\n", + bits_set, mask, nprocs, tbbprocs, env ); if (bits_set !=0 && bits_set!=nprocs) { printf("Warning: sched_getaffinity() returns that we can only use %d out of %d CPUs.\n",bits_set, nprocs); return 2; } + if (env != -1 && nprocs != tbbprocs) + { + printf("Warning: number of threads is set to %d in envirnoment using DEAL_II_NUM_THREADS.\n", env); + return 0; // do not return an error! + } if (nprocs != tbbprocs) { printf("Warning: for some reason TBB only wants to use %d out of %d CPUs.\n", diff --git a/tests/quick_tests/run.cmake b/tests/quick_tests/run.cmake index e941ff0b65..bededcaf2d 100644 --- a/tests/quick_tests/run.cmake +++ b/tests/quick_tests/run.cmake @@ -39,7 +39,8 @@ to the mailing list linked at http://www.dealii.org\n" The affinity test can fail when you are linking in a library like BLAS which uses OpenMP. Even without calling any BLAS functions, OpenMP messes with the thread affinity which causes TBB to run single-threaded only. You -can fix this by exporting OMP_NUM_THREADS=1.\n" +can fix this by exporting OMP_NUM_THREADS=1. Also see GOMP_CPU_AFFINITY +and OMP_PROC_BIND.\n" ) ENDIF()