Skip to content

Instantly share code, notes, and snippets.

@meyer1994
Last active April 21, 2018 00:37
Show Gist options
  • Save meyer1994/c6c1f26abd0f2c3304897e7bbe06e6df to your computer and use it in GitHub Desktop.
Save meyer1994/c6c1f26abd0f2c3304897e7bbe06e6df to your computer and use it in GitHub Desktop.
Test with openmp scopes
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#define TOTAL 1000
#define THREADS 10
long value = 0;
int test() {
#pragma omp for schedule(static)
for (int i = 0; i < TOTAL; i++) {
for (int j = 0; j < TOTAL; j++) {
value++;
}
}
printf("Thread value: %d\n", value);
}
int main(int argc, char* argv[]) {
int total = atoi(argv[1]);
for (int i = 0; i < total; i++) {
#pragma omp parallel num_threads(THREADS) reduction(+:value)
{
test();
}
printf("Main value: %d\n\n", v);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment