From 604c56232ef7201c809f769b6ce36458585b64fc Mon Sep 17 00:00:00 2001 From: Diego Alonso Date: Mon, 9 Dec 2024 12:21:02 +0100 Subject: [PATCH] Make some check examples compilable with OpenMP They contained some wrong directive clauses that either - Referenced not-yet-declared variables - Were missing the datascoping for a referenced variable --- Checks/PWD003/example-omp.c | 2 +- Checks/PWD003/example-omp.f90 | 2 +- Checks/PWD009/README.md | 4 ++-- Checks/PWD009/example-omp.c | 2 +- Checks/PWR006/README.md | 4 ++-- Checks/PWR006/example.c | 2 +- Checks/PWR013/README.md | 4 ++-- Checks/PWR013/example-omp.c | 2 +- Checks/PWR015/example-omp.c | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Checks/PWD003/example-omp.c b/Checks/PWD003/example-omp.c index a128535..b2bf55e 100644 --- a/Checks/PWD003/example-omp.c +++ b/Checks/PWD003/example-omp.c @@ -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]; } diff --git a/Checks/PWD003/example-omp.f90 b/Checks/PWD003/example-omp.f90 index 270de23..e4f23dc 100644 --- a/Checks/PWD003/example-omp.f90 +++ b/Checks/PWD003/example-omp.f90 @@ -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 diff --git a/Checks/PWD009/README.md b/Checks/PWD009/README.md index 1763111..55bb891 100644 --- a/Checks/PWD009/README.md +++ b/Checks/PWD009/README.md @@ -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; @@ -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; diff --git a/Checks/PWD009/example-omp.c b/Checks/PWD009/example-omp.c index 2824b2a..51b47f4 100644 --- a/Checks/PWD009/example-omp.c +++ b/Checks/PWD009/example-omp.c @@ -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; diff --git a/Checks/PWR006/README.md b/Checks/PWR006/README.md index 56c0fcb..71a6ab2 100644 --- a/Checks/PWR006/README.md +++ b/Checks/PWR006/README.md @@ -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]; } @@ -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]; } diff --git a/Checks/PWR006/example.c b/Checks/PWR006/example.c index 10e2dbf..33d7ac3 100644 --- a/Checks/PWR006/example.c +++ b/Checks/PWR006/example.c @@ -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]; } diff --git a/Checks/PWR013/README.md b/Checks/PWR013/README.md index 9aa39cb..2297bdc 100644 --- a/Checks/PWR013/README.md +++ b/Checks/PWR013/README.md @@ -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]; } @@ -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]; } diff --git a/Checks/PWR013/example-omp.c b/Checks/PWR013/example-omp.c index 026fb25..666e9da 100644 --- a/Checks/PWR013/example-omp.c +++ b/Checks/PWR013/example-omp.c @@ -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]; } diff --git a/Checks/PWR015/example-omp.c b/Checks/PWR015/example-omp.c index e74fc2d..3aab03b 100644 --- a/Checks/PWR015/example-omp.c +++ b/Checks/PWR015/example-omp.c @@ -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]; }