1 /******************************************************************************
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
10 * AUTHOR: Blaise Barney 5/99
11 * LAST REVISED: 04/06/05
12 ******************************************************************************/
17 int main (int argc
, char *argv
[]) {
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 */
32 nthreads
= omp_get_num_threads();
33 printf("Number of threads = %d\n", nthreads
);
36 } /* All threads join master thread and disband */