Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//------------------------------------------------------------------------
#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