aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c')
-rw-r--r--gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c b/gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c
new file mode 100644
index 000000000..e33bef316
--- /dev/null
+++ b/gcc-4.9/libgomp/testsuite/libgomp.c/omp_workshare1.c
@@ -0,0 +1,47 @@
+/******************************************************************************
+* FILE: omp_workshare1.c
+* DESCRIPTION:
+* OpenMP Example - Loop Work-sharing - C/C++ Version
+* In this example, the iterations of a loop are scheduled dynamically
+* across the team of threads. A thread will perform CHUNK iterations
+* at a time before being scheduled for the next CHUNK of work.
+* AUTHOR: Blaise Barney 5/99
+* LAST REVISED: 04/06/05
+******************************************************************************/
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define CHUNKSIZE 10
+#define N 100
+
+int main (int argc, char *argv[]) {
+
+int nthreads, tid, i, chunk;
+float a[N], b[N], c[N];
+
+/* Some initializations */
+for (i=0; i < N; i++)
+ a[i] = b[i] = i * 1.0;
+chunk = CHUNKSIZE;
+
+#pragma omp parallel shared(a,b,c,nthreads,chunk) private(i,tid)
+ {
+ tid = omp_get_thread_num();
+ if (tid == 0)
+ {
+ nthreads = omp_get_num_threads();
+ printf("Number of threads = %d\n", nthreads);
+ }
+ printf("Thread %d starting...\n",tid);
+
+ #pragma omp for schedule(dynamic,chunk)
+ for (i=0; i<N; i++)
+ {
+ c[i] = a[i] + b[i];
+ printf("Thread %d: c[%d]= %f\n",tid,i,c[i]);
+ }
+
+ } /* end of parallel section */
+
+ return 0;
+}