testsuite/libgomp.c/omp_hello.c

Go to the documentation of this file.
00001 /******************************************************************************
00002 * FILE: omp_hello.c
00003 * DESCRIPTION:
00004 *   OpenMP Example - Hello World - C/C++ Version
00005 *   In this simple example, the master thread forks a parallel region.
00006 *   All threads in the team obtain their unique thread number and print it.
00007 *   The master thread only prints the total number of threads.  Two OpenMP
00008 *   library routines are used to obtain the number of threads and each
00009 *   thread's number.
00010 * AUTHOR: Blaise Barney  5/99
00011 * LAST REVISED: 04/06/05
00012 ******************************************************************************/
00013 #include <omp.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 
00017 int main (int argc, char *argv[]) {
00018 
00019 int nthreads, tid;
00020 
00021 /* Fork a team of threads giving them their own copies of variables */
00022 #pragma omp parallel private(nthreads, tid)
00023   {
00024 
00025   /* Obtain thread number */
00026   tid = omp_get_thread_num();
00027   printf("Hello World from thread = %d\n", tid);
00028 
00029   /* Only master thread does this */
00030   if (tid == 0) 
00031     {
00032     nthreads = omp_get_num_threads();
00033     printf("Number of threads = %d\n", nthreads);
00034     }
00035 
00036   }  /* All threads join master thread and disband */
00037 
00038   return 0;
00039 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7