Hello world, yet another variant

#include <cstdio>
#include <omp.h>
int main(int argc, char *argv[]) 
{
 omp_set_num_threads(4); 
#pragma omp parallel
 {
   int id = omp_get_thread_num();
   int nproc = omp_get_num_threads(); 
   cout << "Hello world with id number and processes " <<  id <<  nproc << endl;
 } 
return 0;
}

Variables declared outside of the parallel region are shared by all threads If a variable like id is declared outside of the

#pragma omp parallel, 

it would have been shared by various the threads, possibly causing erroneous output

  • Why? What would go wrong? Why do we add possibly?