Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created November 2, 2021 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaityo256/1d78d926fa8f46566ab003e08639ef59 to your computer and use it in GitHub Desktop.
Save kaityo256/1d78d926fa8f46566ab003e08639ef59 to your computer and use it in GitHub Desktop.
OpenMP Schedule Sample
#include <cstdio>
#include <omp.h>
const int N = 8;
int d[N] = {};
int main() {
int tid;
#pragma omp parallel for schedule(static)
for (int i = 0; i < N; i++) {
tid = omp_get_thread_num();
for (int j = 0; j < 1000; j++) {
d[i] += tid;
}
}
for (int i = 0; i < N; i++) {
printf("%d %d\n", i, d[i]);
}
}
@kaityo256
Copy link
Author

I forgot private(tid).

#pragma omp parallel for schedule(static) private(tid)

This is the reason why the behaviours between g++ and icpc werr different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment