aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.4.3/libgomp/testsuite/libgomp.c/omp_hello.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.4.3/libgomp/testsuite/libgomp.c/omp_hello.c')
-rw-r--r--gcc-4.4.3/libgomp/testsuite/libgomp.c/omp_hello.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc-4.4.3/libgomp/testsuite/libgomp.c/omp_hello.c b/gcc-4.4.3/libgomp/testsuite/libgomp.c/omp_hello.c
new file mode 100644
index 000000000..8d58cd43b
--- /dev/null
+++ b/gcc-4.4.3/libgomp/testsuite/libgomp.c/omp_hello.c
@@ -0,0 +1,39 @@
+/******************************************************************************
+* FILE: omp_hello.c
+* DESCRIPTION:
+* OpenMP Example - Hello World - C/C++ Version
+* In this simple example, the master thread forks a parallel region.
+* All threads in the team obtain their unique thread number and print it.
+* The master thread only prints the total number of threads. Two OpenMP
+* library routines are used to obtain the number of threads and each
+* thread's number.
+* AUTHOR: Blaise Barney 5/99
+* LAST REVISED: 04/06/05
+******************************************************************************/
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (int argc, char *argv[]) {
+
+int nthreads, tid;
+
+/* Fork a team of threads giving them their own copies of variables */
+#pragma omp parallel private(nthreads, tid)
+ {
+
+ /* Obtain thread number */
+ tid = omp_get_thread_num();
+ printf("Hello World from thread = %d\n", tid);
+
+ /* Only master thread does this */
+ if (tid == 0)
+ {
+ nthreads = omp_get_num_threads();
+ printf("Number of threads = %d\n", nthreads);
+ }
+
+ } /* All threads join master thread and disband */
+
+ return 0;
+}