Created
February 17, 2014 04:53
-
-
Save kaityo256/9044938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------ | |
#include <stdio.h> | |
#include <vector> | |
#include <time.h> | |
//------------------------------------------------------------------------ | |
const int N_THREADS = 16; | |
//------------------------------------------------------------------------ | |
int | |
func1(int n, int i){ | |
int sum = 0; | |
for(int k=0;k<2;k++){ | |
std::vector <int> v; | |
for(int j=0;j<n;j++){ | |
v.push_back(j*i); | |
} | |
sum = sum + v[n/2]; | |
} | |
return sum; | |
} | |
//------------------------------------------------------------------------ | |
int | |
main(void){ | |
clock_t t1,t2; | |
t1 = clock(); | |
#pragma omp parallel for schedule(static) | |
for(int i=0;i<N_THREADS;i++){ | |
func1(10000000,i); | |
} | |
#pragma omp barrier | |
t2 = clock(); | |
printf("Parallel %d\n",t2-t1); | |
t1 = clock(); | |
func1(10000000,0); | |
t2 = clock(); | |
printf("Serial %d\n",t2-t1); | |
} | |
//------------------------------------------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment