1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <omp.h> // The OpenMP library 4 5 int main(int argc, char * argv[]) { 6 7 int nthreads, nprocs, tid; 8 9 // Request the number of available processors from the 10 // OpenMP library 11 nprocs = omp_get_num_procs(); 12 13 printf("Hello, world! There are %i procs here.\n",nprocs); 14 15 // Use one thread per processor 16 omp_set_num_threads(nprocs); 17 18 // fork a team of threads 19 #pragma omp parallel private(tid) 20 { 21 tid = omp_get_thread_num(); 22 printf("Hello from thread %i\n",tid); 23 24 if(tid==0) { 25 // get the number of threads from the library 26 nthreads = omp_get_num_threads(); 27 28 printf("Number of threads = %i\n",nthreads); 29 30 } 31 } // threads join and terminate 32 33 return 0; 34 } 35