B7 - scheduling
- threads get roughly equal numbers of loop iterations
- some iterations may be more time-consuming
chunks
- contiguous ranges of iterations, the number in a given range being the chunk size
and are the trip-count, number of threads, and the chunk size (if specified)
static scheduling
- allocates chunks before loop execution
- by default:
schedule(static), withchunks of size - with
schedule(static, C), iterations are divided intochunks of size allocated on a round-robin basis
dynamic scheduling
- allocates chunks during loop execution
- the aim is that the fastest processor waits at most
iterations at the end of loop - but the overhead goes up as
decreases schedule(dynamic, C)divides iterations intochunks of size - when a thread finished a chunk, it gets a new one, helping balance the workload
- the disadvantage is scheduling overhead as OpenMP must coordinate the allocation of chunks during execution
- by default,
C=1
guided
schedule(guided, C)works similarly to dynamic scheduling but the chunk size generally decreases as fewer iterations remain up to a specified minimum chunk size- roughly:
- large initial chunks means less scheduling overhead
- small chunks in the end means more flexible distribution of remaining work
- by default,
C=1
runtime
- allows schedule to be set at runtime rather than compilation
- this is specified with environment variable or function call
- eg:
export OMP_SCHEDULE = "static, 4"oromp_set_schedule(omp_sched_static, 4) - useful for experimenting:
export OMP_NUM_THREADS=4
export OMP_SCHEDULE="static,2"
./scheduling
export OMP_SCHEDULE="dynamic,2"
./scheduling
export OMP_SCHEDULE="guided,2"
./scheduling