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 <stdlib.h> 11#include <stdio.h> 12#include <time.h> 13#include <assert.h> 14#include <stdint.h> 15#include <omp.h> 16#include <arch/x86/barrelfish_kpi/asm_inlines_arch.h> 17 18#define WORK_PERIOD 5000000000UL 19#define STACK_SIZE (64 * 1024) 20 21int main(int argc, char *argv[]) 22{ 23 uint64_t now, start; 24 volatile uint64_t workcnt, workload = 0; 25 int64_t workmax = 1000; 26 int64_t i; 27 28 if(argc == 1) { 29 printf("calibrating...\n"); 30 31 do { 32 workload = 0; 33 workmax *= 2; 34 35 start = rdtsc(); 36 37 for(i = 0; i < workmax; i++) { 38 workload++; 39 } 40 41 now = rdtsc(); 42 } while(now - start < WORK_PERIOD); 43 44 // Compute so the max number of CPUs would calc for WORK_PERIOD 45 workmax *= omp_get_num_procs(); 46 47 printf("workmax = %ld\n", workmax); 48 return 0; 49 } else { 50 workmax = atol(argv[1]); 51 } 52 53 int nthreads = omp_get_max_threads(); 54 55 if(argc == 3) { 56 nthreads = atoi(argv[2]); 57 bomp_bomp_init(nthreads); 58 omp_set_num_threads(nthreads); 59 } 60 61 printf("threads %d, workmax %ld, CPUs %d\n", nthreads, workmax, 62 omp_get_num_procs()); 63 64 start = rdtsc(); 65 66 // Do some work 67#pragma omp parallel for private(workcnt) 68 for(i = 0; i < workmax; i++) { 69 workcnt++; 70 } 71 72 now = rdtsc(); 73 74 printf("%s: threads %d, compute time %lu ticks\n", argv[0], nthreads, now - start); 75 76 for(;;); 77 return 0; 78} 79