Search code examples
copenmpschedulesetenv

C, OpenMP, change schedule type, setenv


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.


Solution

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