Skip to content
Advertisement

How to control global OpenMP settings from C/C++?

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).

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement