Skip to content

Instantly share code, notes, and snippets.

@Adiqq
Last active December 13, 2017 21:48
Show Gist options
  • Save Adiqq/abef4ee2e793039079acc7c6006a8214 to your computer and use it in GitHub Desktop.
Save Adiqq/abef4ee2e793039079acc7c6006a8214 to your computer and use it in GitHub Desktop.
#include <omp.h>
#include <assert.h>
#include <stdio.h>
void sum(){
int x,y;
x = y = 10000;
int** A = new int*[x];
for(int i = 0; i < x; ++i)
A[i] = new int[y];
for(int i = 0; i < x; i++){
for(int j = 0; j < y; j++){
A[i][j] = 1;
}
}
long long suma = 0;
double start,stop;
start = omp_get_wtime();
//#pragma omp parallel
{
int j;
//#pragma omp for reduction(+:suma)
for(int i = 0; i < x; i++){
for(j = 0; j < y; j++){
suma += A[i][j];
}
}
}
stop = omp_get_wtime();
assert(suma==100000000ll);
printf("Elapsed time: %lf", stop - start);
for(int i = 0; i < x; ++i)
delete [] A[i];
delete [] A;
}
int main(){
sum();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment