Skip to content

Commit

Permalink
Make some check examples compilable with OpenMP
Browse files Browse the repository at this point in the history
They contained some wrong directive clauses that either
- Referenced not-yet-declared variables
- Were missing the datascoping for a referenced variable
  • Loading branch information
d-alonso committed Dec 9, 2024
1 parent 6975cfa commit a7f4bee
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Checks/PWD003/example-omp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
void example(int *a, int *b, int *sum, int size) {
// Array bounds should be specified
#pragma omp target map(to: a, b) map(from: sum)
#pragma omp parallel for default(none) shared(a, b, sum)
#pragma omp parallel for default(none) shared(a, b, sum, size)
for (int i = 0; i < size; i++) {
sum[i] = a[i] + b[i];
}
Expand Down
2 changes: 1 addition & 1 deletion Checks/PWD003/example-omp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ subroutine example(a, b, sum, size)

! Array bounds should be specified
!$omp target map(to: a, b) map(from: sum)
!$omp parallel do default(none) shared(a, b, sum)
!$omp parallel do default(none) shared(a, b, sum, size)
do i = 1, size
sum(i) = a(i) + b(i)
end do
Expand Down
4 changes: 2 additions & 2 deletions Checks/PWD009/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on non-overlapping positions of the array:
void example(int m, double *A, double *B, double *C) {
double temp;

#pragma omp parallel for default(none) private(i, temp, C) shared(A, B, m)
#pragma omp parallel for default(none) private(temp, C) shared(A, B, m)
for (int i = 0; i < m; i++) {
temp = A[i] * B[i];
C[i] = C[i] + temp;
Expand All @@ -39,7 +39,7 @@ To fix this, `C` should be moved to a `shared` clause:
void example(int m, double *A, double *B, double *C) {
double temp;
#pragma omp parallel for default(none) private(i, temp) shared(A, B, C, m)
#pragma omp parallel for default(none) private(temp) shared(A, B, C, m)
for (int i = 0; i < m; i++) {
temp = A[i] * B[i];
C[i] = C[i] + temp;
Expand Down
2 changes: 1 addition & 1 deletion Checks/PWD009/example-omp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void example(int m, double *A, double *B, double *C) {
double temp;

// "C" should be shared
#pragma omp parallel for default(none) private(i, temp, C) shared(A, B, m)
#pragma omp parallel for default(none) private(temp, C) shared(A, B, m)
for (int i = 0; i < m; i++) {
temp = A[i] * B[i];
C[i] = C[i] + temp;
Expand Down
4 changes: 2 additions & 2 deletions Checks/PWR006/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void example() {
int B[SIZE] = {5, 4, 3, 2, 1};
int sum[SIZE];

#pragma omp parallel for shared(sum) firstprivate(A, B) private(i)
#pragma omp parallel for shared(sum) firstprivate(A, B)
for (int i = 0; i < SIZE; i++) {
sum[i] = A[i] + B[i];
}
Expand All @@ -51,7 +51,7 @@ void example() {
int B[SIZE] = {5, 4, 3, 2, 1};
int sum[SIZE];

#pragma omp parallel for shared(sum, A, B) private(i)
#pragma omp parallel for shared(sum, A, B)
for (int i = 0; i < SIZE; i++) {
sum[i] = A[i] + B[i];
}
Expand Down
2 changes: 1 addition & 1 deletion Checks/PWR006/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void example() {
int B[SIZE] = {5, 4, 3, 2, 1};
int sum[SIZE];

#pragma omp parallel for shared(sum) firstprivate(A, B) private(i)
#pragma omp parallel for shared(sum) firstprivate(A, B)
for (int i = 0; i < SIZE; i++) {
sum[i] = A[i] + B[i];
}
Expand Down
4 changes: 2 additions & 2 deletions Checks/PWR013/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ used:
```c
void example(double *A, double *B, double *C) {
#pragma omp target teams distribute parallel for schedule(auto) shared(A, B) \
private(i) map(to: A[0:100], B[0:100]) map(tofrom: C[0:100])
map(to: A[0:100], B[0:100]) map(tofrom: C[0:100])
for (int i = 0; i < 100; i++) {
C[i] += A[i];
}
Expand All @@ -39,7 +39,7 @@ This can be easily corrected by removing references to B from all the clauses:
```c
void example(double *A, double *B, double *C) {
#pragma omp target teams distribute parallel for schedule(auto) shared(A) \
private(i) map(to: A[0:100]) map(tofrom: C[0:100])
map(to: A[0:100]) map(tofrom: C[0:100])
for (int i = 0; i < 100; i++) {
C[i] += A[i];
}
Expand Down
2 changes: 1 addition & 1 deletion Checks/PWR013/example-omp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void example(double *A, double *B, double *C) {
#pragma omp target teams distribute parallel for schedule(auto) shared(A, B) \
private(i) map(to: A[0:100], B[0:100]) map(tofrom: C[0:100])
map(to: A[0:100], B[0:100]) map(tofrom: C[0:100])
for (int i = 0; i < 100; i++) {
C[i] += A[i];
}
Expand Down
2 changes: 1 addition & 1 deletion Checks/PWR015/example-omp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
void example() {
int A[100], B[100], sum[100];
#pragma omp target map(to: A[0:100], B[0:100]) map(from: sum[0:100])
#pragma omp parallel for private(i)
#pragma omp parallel for
for (int i = 0; i < 50; i++) {
sum[i] = A[i] + B[i];
}
Expand Down

0 comments on commit a7f4bee

Please sign in to comment.