// 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;
}