Is there a way to change the schedule
type in a pragma omp for
loop, using a function in C?
I was trying to do setenv("OMP_SCHEDULE", "guided", 1);
before the parallel statement, but I am not completely sure if it works, since the times that I get from my code are very similar.
What I wanted to do is to use a for
loop changing the schedule type to compare the timings, giving dynamic
, auto
, etc. as a string in the setenv
function.

- 843
- 2
- 16
- 36
-
1Use schedule(runtime) and set OMP_SCHEDULE. See the last paragraph of this answer http://stackoverflow.com/questions/10850155/openmp-for-schedule/10852852#10852852 – Z boson Feb 28 '14 at 08:30
2 Answers
You can use schedule(runtime) and set OMP_SCHEDULE.
From https://computing.llnl.gov/tutorials/openMP/
RUNTIME The scheduling decision is deferred until runtime by the environment variable OMP_SCHEDULE. It is illegal to specify a chunk size for this clause.
Let me just quote Hristo Iliev since he already said it best here OpenMP: for schedule
Since precompiled code could be run on various platforms it would be nice if the end user can control the scheduling. That's why OpenMP provides the special schedule(runtime) clause. With runtime scheduling the type is taken from the content of the environment variable OMP_SCHEDULE. This allows to test different scheduling types without recompiling the application and also allows the end user to fine-tune for his or her platform.
-
Does schedule(runtime) guarantee that the environment variable will be read each time the loop is invoked, or might the runtime read the variable once at startup? – pburka Mar 09 '14 at 03:33
There is no standard way to do this, but if you're using Intel's library, you can use the kmp_set_defaults()
extension. This takes a string of options separated by |
characters, and overrides default OpenMP behavior. In your example, kmp_set_defaults("OMP_SCHEDULE=guided")
ought to accomplish what you want.

- 1,434
- 9
- 12