/******************************************************** *** Switch to bash Shell if you are not already there. *** bash-4.1$ gcc -fopenmp -Wall -Werror example1OMP.c -o a.out bash-4.1$ export OMP_NUM_THREADS=10 (For tcsh setenv OMP_NUM_THREADS 10) bash-4.1$ ./a.out Hello World from thread = 6 Hello World from thread = 1 Hello World from thread = 9 Hello World from thread = 2 Hello World from thread = 3 Hello World from thread = 4 Hello World from thread = 5 Hello World from thread = 7 Hello World from thread = 8 Hello World from thread = 0 Number of threads = 10 **********************************************************/ #include #include int main () { int nthreads, tid; /* Fork a team of threads giving them their own copies of variables */ #pragma omp parallel private(tid) { /* Obtain and print thread id */ tid = omp_get_thread_num(); printf("Hello World from thread = %d\n", tid); /* Only master thread does this */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } /* End of parallel section. All Thread join master thread and terminate */ /* Implicit barrier at the end of the parallel region */ return 0; }