Schecule¶
Static¶
The default schedule scheme is “static” when it is not specified in for construct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h>
#include <omp.h>
int main ()
{
int i, N;
N = 6;
#pragma omp parallel
{
#pragma omp for
for (i = 0; i < 6; i++)
printf("Loop 1: iter %3d, thread_id %3d\n", i, omp_get_thread_num());
#pragma omp for
for (i = 0; i < 6; i++)
printf("Loop 2: iter %3d, thread_id %3d\n", i, omp_get_thread_num());
}
return 0;
}
|
Dynamic¶
There are two ways of setting “dynamic” schedule:
dynamic schedule by for construct
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <stdio.h> #include <omp.h> int main () { int i, N; N = 6; #pragma omp parallel { #pragma omp for schedule(dynamic,1) for (i = 0; i < 6; i++) printf("Loop 1: iter %3d, thread_id %3d\n", i, omp_get_thread_num()); #pragma omp for schedule(dynamic,1) for (i = 0; i < 6; i++) printf("Loop 2: iter %3d, thread_id %3d\n", i, omp_get_thread_num()); } return 0; }
dynamic schedule by environment variables
1
export OMP_SCHEDULE=“dynamic,1”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <stdio.h> #include <omp.h> int main () { int i, N; N = 6; #pragma omp parallel { #pragma omp for for (i = 0; i < 6; i++) printf("Loop 1: iter %3d, thread_id %3d\n", i, omp_get_thread_num()); #pragma omp for for (i = 0; i < 6; i++) printf("Loop 2: iter %3d, thread_id %3d\n", i, omp_get_thread_num()); } return 0; }