View Source

{section:border=true}
{column:width=70%}

h2. Routines for Runtime Scheduling in OpenMP 3.0

In 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)
Section 3.2.11: omp_set_schedule runtime routine
Section 3.2.12: omp_get_schedule runtime routine

*Example (Fortran):*
{noformat}
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
{noformat}
*Example (C/C++):*
{noformat}
#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
{noformat}
{column}
{column:width=30%}
{panel:title=OpenMP 3.0 Features in Express 7.08}
{children:page=Sun Studio OpenMP}
{panel}
{column}
{section}

The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact