Last active
August 29, 2015 14:01
-
-
Save aprell/3ecdb8bcd1e862104a87 to your computer and use it in GitHub Desktop.
Examples of implicit barriers in OpenMP and Cilk Plus
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 <unistd.h> | |
#include <cilk/cilk.h> | |
int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
int main(void) | |
{ | |
int i; | |
cilk_for (i = 0; i < 10; i++) { | |
A[i] += 42; | |
sleep(1); | |
} // Implicit barrier | |
for (i = 0; i < 10; i++) { | |
printf("%d\n", A[i]); | |
} | |
return 0; | |
} |
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 <unistd.h> | |
#include <omp.h> | |
int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
int main(void) | |
{ | |
int i; | |
#pragma omp parallel num_threads(8) | |
{ | |
#pragma omp single | |
for (i = 0; i < 10; i++) { | |
#pragma omp task shared(A) firstprivate(i) | |
{ A[i] += 42; sleep(1); } | |
} // Implicit barrier | |
} // Implicit barrier | |
for (i = 0; i < 10; i++) { | |
printf("%d\n", A[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment