1 /******************************************************************************
2 * FILE: omp_workshare2.c
4 * OpenMP Example - Sections Work-sharing - C/C++ Version
5 * In this example, the OpenMP SECTION directive is used to assign
6 * different array operations to threads that execute a SECTION. Each
7 * thread receives its own copy of the result array to work with.
8 * AUTHOR: Blaise Barney 5/99
9 * LAST REVISED: 04/06/05
10 ******************************************************************************/
16 int main (int argc, char *argv[]) {
19 float a[N], b[N], c[N];
21 /* Some initializations */
23 a[i] = b[i] = i * 1.0;
25 #pragma omp parallel shared(a,b,nthreads) private(c,i,tid)
27 tid = omp_get_thread_num();
30 nthreads = omp_get_num_threads();
31 printf("Number of threads = %d\n", nthreads);
33 printf("Thread %d starting...\n",tid);
35 #pragma omp sections nowait
39 printf("Thread %d doing section 1\n",tid);
43 printf("Thread %d: c[%d]= %f\n",tid,i,c[i]);
49 printf("Thread %d doing section 2\n",tid);
53 printf("Thread %d: c[%d]= %f\n",tid,i,c[i]);
57 } /* end of sections */
59 printf("Thread %d done.\n",tid);
61 } /* end of parallel section */