Pointer Loop Control Variable for C and C++ in OpenMP 3.0In OpenMP Specification Version 3.0, the control variable of a loop associated with a for directive can be of pointer type. See Section 2.5.1 on p. 38 of the OpenMP 3.0 Specification. Example (C/C++): #include <stdio.h> #include <stdlib.h> #include <omp.h> #define SIZE 10 int main(void) { int *buffer, *base, *end, *p; int i; omp_set_dynamic(0); omp_set_num_threads(10); buffer = (int *) malloc (SIZE * sizeof (int)); base = buffer; end = &buffer[SIZE]; i = 0; #pragma omp parallel for shared(i, base, end) private(p) ordered for (p = base; p < end ; ++p) { #pragma omp ordered { *p = i; i++; } } for (i = 0; i < SIZE; i++) { printf ("%d\n", buffer[i]); } return 0; } % cc -xopenmp -xO3 pointer_loop.c % a.out 0 1 2 3 4 5 6 7 8 9 |
OpenMP 3.0 Features in Express 11.08
|