Created
December 13, 2017 21:52
-
-
Save Adiqq/cf888d96d8d0dacd9bb65cfcdbc67f46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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, sumal; | |
#pragma omp for | |
for(int i = 0; i < x; i++){ | |
for(j = 0; j < y; j++){ | |
sumal += A[i][j]; | |
} | |
} | |
#pragma omp atomic | |
suma += sumal; | |
} | |
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