Routines for Runtime Scheduling in OpenMP 3.0In OpenMP 3.0, a new Internal Control Variable (ICV), called run-sched-var, has been introduced, and two new runtime routines to set/get the RUNTIME schedule have been added. See the following related sections in the OpenMP specification: Section 2.3 : run-sched-var internal control variable (ICV) Example (Fortran): include "omp_lib.h"
integer kind, modifier
call omp_set_dynamic(.false.)
call omp_set_num_threads(10)
print *, "Num threads =", omp_get_num_threads()
print *, "Max threads =", omp_get_max_threads()
call omp_set_schedule(omp_sched_static, 11)
call omp_get_schedule(kind, modifier)
print *, "Schedule: kind =", kind, "modifier =", modifier
call omp_set_schedule(omp_sched_dynamic, 12)
call omp_get_schedule(kind, modifier)
print *, "Schedule: kind =", kind, "modifier =", modifier
call omp_set_schedule(omp_sched_guided, 13)
call omp_get_schedule(kind, modifier)
print *, "Schedule: kind =", kind, "modifier =", modifier
call omp_set_schedule(omp_sched_auto, 14)
call omp_get_schedule(kind, modifier)
print *, "Schedule: kind =", kind, "modifier =", modifier
call omp_set_schedule(sunw_mp_sched_reserved, 1501)
call omp_get_schedule(kind, modifier)
print *, "Schedule: kind =", kind, "modifier =", modifier
end
% f90 -xopenmp -xO3 test.f
% a.out
Num threads = 1
Max threads = 10
Schedule: kind = 1 modifier = 11
Schedule: kind = 2 modifier = 12
Schedule: kind = 3 modifier = 13
Schedule: kind = 4 modifier = 0
Schedule: kind = 1 modifier = 0
Example (C/C++): #include "omp.h"
#include <stdio.h>
int main()
{
int i, x;
omp_sched_t runtime_sched;
int runtime_chunk;
omp_set_dynamic(0);
omp_set_num_threads(4);
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
omp_set_schedule(omp_sched_auto, 10);
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
x = 0;
#pragma omp parallel private(runtime_sched, runtime_chunk)
{
if (omp_get_thread_num() == 0) {
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
}
#pragma omp barrier
if (omp_get_thread_num() > 0) {
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
}
#pragma omp barrier
#pragma omp for ordered schedule (runtime)
for (i = 0; i <= 10; i++)
{
#pragma omp atomic
x += 1;
#pragma omp ordered
{
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
}
}
}
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
omp_set_schedule(omp_sched_guided, 20);
omp_get_schedule (&runtime_sched, &runtime_chunk);
printf ("runtime schedule = %d, chunk = %d\n", runtime_sched, runtime_chunk);
}
% cc -xopenmp -xO3 test.c
% setenv OMP_SCHEDULE DYNAMIC,5
% a.out
runtime schedule = 2, chunk = 5
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 4, chunk = 0
runtime schedule = 3, chunk = 20
|
OpenMP 3.0 Features in Express 7.08
|