
using namespace std;

#include <iostream> 
#include <omp.h> 

int main(int argc, char *argv[]) 
{ 
   int nthreads;
   int myid;

   /* make the values of nthreads and myid private to each thread */ 

#pragma omp parallel private (nthreads, myid) // Thread has its own myid !!!
   { 
      /* ------------------------------
	 Every thread does this
	 ------------------------------ */
      myid = omp_get_thread_num(); 

      cout << "Hello I am thread " << myid << endl; 

      /* ------------------------------
	 Only thread 0 does this
	 ------------------------------ */
      if (myid == 0) 
      { 
         nthreads = omp_get_num_threads(); 
         cout << "Number of threads = " << nthreads << endl; 
      } 

   } 
   return 0; 
} 

