1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <omp.h> 4 #include <sys/sysconf.h> 5 main(int argc,char * argv[])6int main (int argc, char *argv[]) 7 { 8 int nthreads, tid; 9 printf("SC_NPROCESSORS_ONLN: %d\n", sysconf (_SC_NPROCESSORS_ONLN)); 10 printf("SC_NPROCESSORS_CONF: %d\n", sysconf (_SC_NPROCESSORS_CONF)); 11 #pragma omp parallel default(shared) private(nthreads, tid) 12 /* Fork a team of threads giving them their own copies of variables */ 13 { 14 /* Obtain thread number */ 15 tid = omp_get_thread_num(); 16 printf("Hello World from thread = %d\n", tid); 17 /* Only master thread does this */ 18 if (tid == 0) 19 { 20 nthreads = omp_get_num_threads(); 21 printf("Number of threads = %d\n", nthreads); 22 } 23 } /* All threads join master thread and disband */ 24 25 return 0; 26 } 27