Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created February 17, 2014 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaityo256/9044938 to your computer and use it in GitHub Desktop.
Save kaityo256/9044938 to your computer and use it in GitHub Desktop.
//------------------------------------------------------------------------
#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