Last active
August 29, 2015 14:07
-
-
Save Garciat/f5ec63cfa385f0bc69e8 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
// compile with: gcc openmp.c -o openmp -std=c11 -O3 -Wall -fopenmp | |
#include <stdio.h> | |
#include <stdlib.h> | |
typedef int num; | |
int main(int argc, char *argv[]) { | |
int n = 20000; | |
int m = 20000; | |
num *p = (num*)malloc(n * m * sizeof(num)); | |
if (p == NULL) | |
return 1; | |
for (int i = 0; i < n * m; ++i) { | |
p[i] = 1; | |
} | |
num s = 0; | |
#pragma omp parallel for | |
for (int i = 0; i < n; ++i) { | |
num ss = 0; | |
for (int j = 0; j < m; ++j) { | |
ss += p[i * m + j]; | |
} | |
#pragma omp atomic | |
s += ss; | |
} | |
printf("%lld\n", s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment