1 /******************************************************************************
2 * FILE: omp_workshare1.c
4 * OpenMP Example - Loop Work-sharing - C/C++ Version
5 * In this example, the iterations of a loop are scheduled dynamically
6 * across the team of threads. A thread will perform CHUNK iterations
7 * at a time before being scheduled for the next CHUNK of work.
8 * AUTHOR: Blaise Barney 5/99
9 * LAST REVISED: 04/06/05
10 ******************************************************************************/
17 int main (int argc, char *argv[]) {
19 int nthreads, tid, i, chunk;
20 float a[N], b[N], c[N];
22 /* Some initializations */
24 a[i] = b[i] = i * 1.0;
27 #pragma omp parallel shared(a,b,c,nthreads,chunk) private(i,tid)
29 tid = omp_get_thread_num();
32 nthreads = omp_get_num_threads();
33 printf("Number of threads = %d\n", nthreads);
35 printf("Thread %d starting...\n",tid);
37 #pragma omp for schedule(dynamic,chunk)
41 printf("Thread %d: c[%d]= %f\n",tid,i,c[i]);
44 } /* end of parallel section */