Reputation: 557
OpenMP doesn't provide API to adjust some crucial settings in runtime, e.g. OMP_WAIT_POLICY or GOMP_SPINCOUNT (at least in gcc 4.8.3). Such settings are designed to be changed through environment variables for some reason. Not very convenient.
Is there any way I can change such settings in run-time from C/C++ using gcc on Linux?
For example, would it be enough to change corresponding environment variables (e.g. by putenv
from stdlib.h?). Will OpenMP kernel pick-up the new settings right away or does it read them only once on process start?
P.S. On Windows Intel C++/Fortran provide additional functions for the settings (e.g. kmp_set_blocktime).
Upvotes: 0
Views: 591
Reputation: 74365
The OpenMP standard defines a set of internal control variables (ICVs) that influence the working of the runtime. Those ICVs are initialised from the values of certain environment variables and then some of them can be read and/or modified by using a set of standard OpenMP API calls.
The list of ICVs and their meaning is given in §2.3.1 of the OpenMP reference. The list of API calls that can be used to retrieve of modify the values of certain ICVs is given in §2.3.3.
Anything besides what is listed in the OpenMP reference is non-standard and using it will result in non-portable source codes. Also, hardcoding certain OpenMP settings into the program code takes away from the end user the ability to modify the runtime behaviour without the need to recompile. The presumption behind having those ICVs controlled by environment variables is that there are far more execution environments than you as a programmer could imagine.
Upvotes: 2
Reputation: 9489
The OpenMP standard explicitly says:
Modifications to the environment variables after the program has started, even if modified by the program itself, are ignored by the OpenMP implementation. However, the settings of some of the ICVs can be modified during the execution of the OpenMP program by the use of the appropriate directive clauses or OpenMP API routines.
So if no handles are given, either through a compiler directive, or through a run-time library routine, you cannot modify these values once the code started.
Of course, since GOMP_SPINCOUNT
isn't a standardised environment variable, it may not comply with the OpenMP standard requirements... But that's all I can say.
Upvotes: 3