Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c / omp_hello.c
blob8d58cd43bf62506fcf8957e6fa7b6eaa4ae7e1f2
1 /******************************************************************************
2 * FILE: omp_hello.c
3 * DESCRIPTION:
4 * OpenMP Example - Hello World - C/C++ Version
5 * In this simple example, the master thread forks a parallel region.
6 * All threads in the team obtain their unique thread number and print it.
7 * The master thread only prints the total number of threads. Two OpenMP
8 * library routines are used to obtain the number of threads and each
9 * thread's number.
10 * AUTHOR: Blaise Barney 5/99
11 * LAST REVISED: 04/06/05
12 ******************************************************************************/
13 #include <omp.h>
14 #include <stdio.h>
15 #include <stdlib.h>
17 int main (int argc, char *argv[]) {
19 int nthreads, tid;
21 /* Fork a team of threads giving them their own copies of variables */
22 #pragma omp parallel private(nthreads, tid)
25 /* Obtain thread number */
26 tid = omp_get_thread_num();
27 printf("Hello World from thread = %d\n", tid);
29 /* Only master thread does this */
30 if (tid == 0)
32 nthreads = omp_get_num_threads();
33 printf("Number of threads = %d\n", nthreads);
36 } /* All threads join master thread and disband */
38 return 0;