testsuite/libgomp.c/omp_workshare4.c

Go to the documentation of this file.
00001 /******************************************************************************
00002 * OpenMP Example - Combined Parallel Loop Work-sharing - C/C++ Version
00003 * FILE: omp_workshare4.c
00004 * DESCRIPTION:
00005 *   This is a corrected version of the omp_workshare3.c example. Corrections
00006 *   include removing all statements between the parallel for construct and
00007 *   the actual for loop, and introducing logic to preserve the ability to 
00008 *   query a thread's id and print it from inside the for loop.
00009 * SOURCE: Blaise Barney  5/99
00010 * LAST REVISED: 03/03/2002
00011 ******************************************************************************/
00012 
00013 #include <omp.h>
00014 #include <stdio.h>
00015 #define N       50
00016 #define CHUNKSIZE   5
00017 
00018 main ()  {
00019 
00020 int i, chunk, tid;
00021 float a[N], b[N], c[N];
00022 char first_time;
00023 
00024 /* Some initializations */
00025 for (i=0; i < N; i++)
00026   a[i] = b[i] = i * 1.0;
00027 chunk = CHUNKSIZE;
00028 first_time = 'y';
00029 
00030 #pragma omp parallel for     \
00031   shared(a,b,c,chunk)            \
00032   private(i,tid)             \
00033   schedule(static,chunk)     \
00034   firstprivate(first_time)
00035 
00036   for (i=0; i < N; i++)
00037     {
00038     if (first_time == 'y')
00039       {
00040       tid = omp_get_thread_num();
00041       first_time = 'n';
00042       }
00043     c[i] = a[i] + b[i];
00044     printf("tid= %d i= %d c[i]= %f\n", tid, i, c[i]);
00045     }
00046 
00047   return 0;
00048 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7