1/** 2 * \file 3 * \brief libbomp test. 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <stdio.h> 16#include <omp.h> 17#include <stdlib.h> 18#include <stdint.h> 19#include <assert.h> 20 21#ifdef POSIX 22static inline uint64_t rdtsc(void) 23{ 24 uint32_t eax, edx; 25 __asm volatile ("rdtsc" : "=a" (eax), "=d" (edx)); 26 return ((uint64_t)edx << 32) | eax; 27} 28#endif 29 30#define N 10000000 31 32int main(int argc, char *argv[]) 33{ 34 uint64_t begin, end; 35 int i; 36 static int a[N]; 37 38 assert(argc == 2); 39#ifndef POSIX 40 bomp_bomp_init(atoi(argv[1])); 41#endif 42 43 omp_set_num_threads(atoi(argv[1])); 44 45 for (i=0;i<N;i++) a[i]= 2*i; 46 47 begin = rdtsc(); 48 49#pragma omp parallel for 50 for (i=0;i<N;i++) a[i]= 2*i; 51 52 end = rdtsc(); 53 54 printf("Value of sum is %d, time taken %lu\n", 0, end - begin); 55} 56