Last active
April 21, 2018 00:37
-
-
Save meyer1994/c6c1f26abd0f2c3304897e7bbe06e6df to your computer and use it in GitHub Desktop.
Test with openmp scopes
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
#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