8 #define ITERATIONS 100000
10 pthread_barrier_t barr;
12 static __inline__ unsigned long long rdtsc(void)
15 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
16 return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
19 static __inline__ int64_t timeInMS () //time in microsec
23 gettimeofday(&t, NULL);
25 (int64_t)t.tv_sec * 1000000 +
34 unsigned long long tottime, time;
35 while(count<ITERATIONS) {
36 // Wait till we may fire away
37 int rc=pthread_barrier_wait(&barr);
38 if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD)
40 printf("Could not wait on barrier\n");
43 //printf("t= %lld\n", rdtsc());
49 printf("time= %lld micro secs\n", tottime/ITERATIONS);
57 pthread_t t1, t2, t3, t4, t5, t6, t7, t8;
60 // Barrier initialization
61 if(pthread_barrier_init(&barr, NULL, THREADS))
63 printf("Could not create a barrier\n");
67 pthread_create(&t1, NULL, thd, NULL);
68 pthread_create(&t2, NULL, thd, NULL);
69 pthread_create(&t3, NULL, thd, NULL);
70 pthread_create(&t4, NULL, thd, NULL);
71 pthread_create(&t5, NULL, thd, NULL);
72 pthread_create(&t6, NULL, thd, NULL);
73 pthread_create(&t7, NULL, thd, NULL);
74 pthread_create(&t8, NULL, thd, NULL);
76 pthread_join(t1, NULL);
77 pthread_join(t2, NULL);
78 pthread_join(t3, NULL);
79 pthread_join(t4, NULL);
80 pthread_join(t5, NULL);
81 pthread_join(t6, NULL);
82 pthread_join(t7, NULL);
83 pthread_join(t8, NULL);