Conversation
…HREADS If openMP is available, the value of command line --threads-per-process will determine how many threads will be used. The default number is 2 if command line argument is not used. To let OpenMP determine how many threads will be used use value -1 for the command line argument. In this case either the same number of threads as logical CPUs will be used if the environment variable OMP_NUM_THREADS is not set. If it is set then that number will be used.
|
jenkins build this please |
| constexpr int default_threads = 2; | ||
| const bool isSet = Parameters::IsSet<Parameters::ThreadsPerProcess>(); | ||
| const int requested_threads = Parameters::Get<Parameters::ThreadsPerProcess>(); | ||
| int threads = requested_threads > 0 ? requested_threads : default_threads; |
There was a problem hiding this comment.
It seems to me that setting --threads-per-process=-1 did nothing in the current master, good to fix that!
However, on line 350, the variable threads is used. Should that be requested_threads? Reason: If we pass -1 on the command line and the environment variable is 1 we get a warning, because threads is 2, but the code will run without calling omp_set_num_threads() at all, which means (probably?) that the environment variable value will be used (=1).
| threads = omp_num_threads; | ||
| if (isSet) { | ||
| OpmLog::warning("Environment variable OMP_NUM_THREADS takes precedence over the --threads-per-process cmdline argument."); | ||
| if (isSet && threads > omp_num_threads) { |
There was a problem hiding this comment.
One could also argue that this warning is not important and the entire reading of the variable can be deleted. Not sure though!
There was a problem hiding this comment.
After some discussion, I have changed my mind: It is important. However it may be misleading as worded now. I have assumed that an explicit call to omp_set_num_threads() wins over the enviroment variable, however I have now learned that OMP_NUM_THREADS is used to set the size of the thread pool at program start. Therefore there is no way the program will actually use a larger number of threads than that, no matter what we pass to omp_set_num_threads(). So the warning should probably not say "Using specified value anyway", but "OMP_NUM_THREADS sets the maximum number of threads, so the specified value is ignored."
If OpenMP is available, the value of command line --threads-per-process will determine how many threads will be used. The default number is 2 if command line argument is not used. To let OpenMP determine how many threads will be used use value -1 for the command line argument. In this case either the same number of threads as logical CPUs will be used if the environment variable OMP_NUM_THREADS is not set. If it is set then that number will be used.
Previously the values set in the environment variable OPM_NUM_THREADS always took precedence