${fontLinkMarker}

Alin Marin Elena's

Republic of Numbers and Letters
 1 /*    Copyright (c) 2014 Alin Marin Elena <alinm.elena@gmail.com>
 2       The MIT License http://opensource.org/licenses/MIT*/
 3 #include <stdio.h>
 4 #include <omp.h>
 5 #include <sched.h>
 6 
 7 void testThreads();
 8 
 9 int main(int argc,char **argv)
10 {  
11   testThreads();
12   return 0;
13 }
14   
15 void testThreads()
16 {
17   int tCount,threadsMax,tid;   
18 #ifdef __MIC__
19   printf("Running on Xeon Phi\n");
20 #else
21   printf("Running on host\n");
22 #endif //__MIC__
23   threadsMax=omp_get_max_threads();
24   #pragma omp parallel default(none) private(tid) shared(tCount,threadsMax)
25   {
26     tid = omp_get_thread_num();
27     #pragma omp critical
28       printf("Hello from thread id %d on core %d\n",tid,sched_getcpu());
29     #pragma omp barrier 
30     #pragma omp master
31     {
32       tCount = omp_get_num_threads();
33       printf("The number of threads is %d\n", tCount);
34       printf("Maximum number of threads is %d\n", threadsMax);
35       printf("================================\n");
36     }
37   }
38 }