I have a piece of code (which is part of an application) that I'm trying to optimize using OpenMP, am trying out various scheduling policies. In my case, I noticed that the schedule(RUNTIME)
clause has an edge over others (I am not specifying a chunk_size). I've two questions:
When I do not specify chunk_size, is there a difference between schedule(DYNAMIC)
and schedule(GUIDED)
?
How does OpenMP determine the default implementation-specific scheduling that is stored in the OMP_SCHEDULE
variable?
I learned that if no scheduling scheme is specified, then by default schedule(STATIC)
is used. So if I don't modify the OMP_SCHEDULE
variable, and use schedule(RUNTIME)
in my program, would the scheduling scheme be schedule(STATIC)
all the times or does OpenMP have some intelligent way to dynamically devise the schedule strategy and change it from time to time?
The schedule clause tells OpenMP how to distribute the loop iterations to the threads.
The nice thing with static scheduling is that OpenMP run-time guarantees that if you have two separate loops with the same number of iterations and execute them with the same number of threads using static scheduling, then each thread will receive exactly the same iteration range(s) in both parallel regions.
Static Schedules By default, OpenMP statically assigns loop iterations to threads. When the parallel for block is entered, it assigns each thread the set of loop iterations it is to execute.
guided is an OpenMP schedule policy. The set of iterations is split in blocks of consecutive iterations called chunks, which are distributed to the threads in the team. Each thread executes a chunk, then requests another chunk, until no chunks remain to be distributed.
Yes, if you do not specify a chunk size then DYNAMIC will make the size of all chunks 1. But GUIDED will make the minimum chunk size 1 but other chunk sizes will be implementation dependent. Perhaps you could figure out your situation by running some experiments or reading the documentation.
As I understand the situation: if the environment variable OMP_SCHEDULE is not set then the runtime schedule is implementation dependent. I think it would be very odd if the same schedule was not chosen for each execution of the program. I do not believe that OpenMP, which is a set of compile-time directives, has any way to understand the run-time performance of your program and to choose a schedule based on such information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With