1/* 2 * Copyright (c) 2009, 2010, 2011, ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#include <assert.h> 11#include <stdbool.h> 12#include <stdlib.h> 13#include <stdio.h> 14#include <time.h> 15#include <assert.h> 16#include <stdint.h> 17#include <omp.h> 18 19#define ITERATIONS 1000000 20#define STACK_SIZE (64 * 1024) 21#define MAXTHREADS 16 22 23static inline uint64_t rdtsc(void) 24{ 25 uint64_t eax, edx; 26 __asm volatile ("rdtsc" : "=a" (eax), "=d" (edx)); 27 return (edx << 32) | eax; 28} 29 30int main(int argc, char *argv[]) 31{ 32 int nthreads = 1; 33 static uint64_t starta[MAXTHREADS][ITERATIONS]; 34 35 if(argc == 2) { 36 nthreads = atoi(argv[1]); 37 backend_span_domain(14, STACK_SIZE); 38 bomp_custom_init(NULL); 39 omp_set_num_threads(nthreads); 40 } else { 41 assert(!"Specify number of threads"); 42 } 43 44 // Do some work 45#pragma omp parallel 46 { 47 bomp_synchronize(); 48 49 for(uint64_t i = 0; i < ITERATIONS; i++) { 50 uint64_t lasta = rdtsc(); 51#pragma omp barrier 52 starta[omp_get_thread_num()][i] = rdtsc() - lasta; 53 } 54 } 55 56 static uint64_t hgram[15] = { 0 }; 57 58 for(int i = 0; i < ITERATIONS; i++) { 59 for(int n = 0; n < nthreads; n++) { 60 uint64_t val = starta[n][i]; 61 for(int j = 0; j < 15; j++) { 62 val /= 10; 63 if(val == 0) { 64 hgram[j]++; 65 break; 66 } 67 } 68 } 69 } 70 71 uint64_t val = 1; 72 for(int i = 0; i < 15; i++) { 73 val *= 10; 74 if(hgram[i] > 0) { 75 printf("%lu\t%lu\n", val, hgram[i]); 76 } 77 } 78 79 for(;;); 80 return 0; 81} 82