00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <omp.h>
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #define CHUNKSIZE 10
00015 #define N 100
00016
00017 int main (int argc, char *argv[]) {
00018
00019 int nthreads, tid, i, chunk;
00020 float a[N], b[N], c[N];
00021
00022
00023 for (i=0; i < N; i++)
00024 a[i] = b[i] = i * 1.0;
00025 chunk = CHUNKSIZE;
00026
00027 #pragma omp parallel shared(a,b,c,nthreads,chunk) private(i,tid)
00028 {
00029 tid = omp_get_thread_num();
00030 if (tid == 0)
00031 {
00032 nthreads = omp_get_num_threads();
00033 printf("Number of threads = %d\n", nthreads);
00034 }
00035 printf("Thread %d starting...\n",tid);
00036
00037 #pragma omp for schedule(dynamic,chunk)
00038 for (i=0; i<N; i++)
00039 {
00040 c[i] = a[i] + b[i];
00041 printf("Thread %d: c[%d]= %f\n",tid,i,c[i]);
00042 }
00043
00044 }
00045
00046 return 0;
00047 }