Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c / omp_workshare1.c
blobe33bef316d801bf29bdf0ff534ba638be47c26ba
1 /******************************************************************************
2 * FILE: omp_workshare1.c
3 * DESCRIPTION:
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 ******************************************************************************/
11 #include <omp.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #define CHUNKSIZE 10
15 #define N 100
17 int main (int argc, char *argv[]) {
19 int nthreads, tid, i, chunk;
20 float a[N], b[N], c[N];
22 /* Some initializations */
23 for (i=0; i < N; i++)
24 a[i] = b[i] = i * 1.0;
25 chunk = CHUNKSIZE;
27 #pragma omp parallel shared(a,b,c,nthreads,chunk) private(i,tid)
29 tid = omp_get_thread_num();
30 if (tid == 0)
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)
38 for (i=0; i<N; i++)
40 c[i] = a[i] + b[i];
41 printf("Thread %d: c[%d]= %f\n",tid,i,c[i]);
44 } /* end of parallel section */
46 return 0;