Unsigned int Loop Control Variable for C and C++ in OpenMP 3.0In OpenMP 3.0, the control variable of a loop associated with a for directive can be of signed or unsigned integer type. In OpenMP 2.5, only signed integer type was allowed. SeeSection 2.5.1 on p. 38 of the OpenMP 3.0 Specification. Example (C/C++): #include <stdio.h>
#include <omp.h>
#define N 20
int main ()
{
float a[N];
omp_set_dynamic(0);
omp_set_num_threads(10);
for (int i=0; i<N; ++i) {
a[i] = i;
}
#pragma omp parallel shared(a)
{
#pragma omp for
for (unsigned int i=0; i<N; ++i) {
a[i] = a[i] * 2.0;
}
#pragma omp for
for (unsigned long j=0; j<N; ++j) {
a[j] = a[j] * 2.0;
}
}
for (int i=0; i<N; i++) {
printf ("%i: %f\n", i, a[i]);
}
}
% cc -xopenmp -xO3 test.c
% a.out
0: 0.000000
1: 4.000000
2: 8.000000
3: 12.000000
4: 16.000000
5: 20.000000
6: 24.000000
7: 28.000000
8: 32.000000
9: 36.000000
10: 40.000000
11: 44.000000
12: 48.000000
13: 52.000000
14: 56.000000
15: 60.000000
16: 64.000000
17: 68.000000
18: 72.000000
19: 76.000000
|
OpenMP 3.0 Features in Express 7.08
|