Skip to content

Commit e5d66ea

Browse files
committed
Add <atomic> include and fix OpenMP shared directive
Include the <atomic> header where needed to ensure proper functionality. Update OpenMP parallel region directives to explicitly declare the shared variable `counter` to avoid potential issues.
1 parent 76dd44a commit e5d66ea

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

tasks/example/all/src/ops_all.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <mpi.h>
44

5+
#include <atomic>
56
#include <cmath>
67
#include <cstddef>
78
#include <functional>
@@ -44,7 +45,7 @@ bool NesterovATestTaskALL::RunImpl() {
4445
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4546
if (rank == 0) {
4647
std::atomic<int> counter(0);
47-
#pragma omp parallel default(none)
48+
#pragma omp parallel default(none) shared(counter)
4849
{
4950
counter++;
5051
}
@@ -62,7 +63,7 @@ bool NesterovATestTaskALL::RunImpl() {
6263
}
6364
GetOutput() /= counter;
6465

65-
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int i) { counter--; });
66+
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter--; });
6667
GetOutput() += counter;
6768

6869
MPI_Barrier(MPI_COMM_WORLD);

tasks/example/omp/src/ops_omp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "example/omp/include/ops_omp.hpp"
22

3+
#include <atomic>
34
#include <cmath>
45
#include <cstddef>
56
#include <vector>
@@ -34,7 +35,7 @@ bool NesterovATestTaskOMP::RunImpl() {
3435
GetOutput() *= num_threads;
3536

3637
std::atomic<int> counter(0);
37-
#pragma omp parallel default(none)
38+
#pragma omp parallel default(none) shared(counter)
3839
{
3940
counter++;
4041
}

tasks/example/stl/src/ops_stl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "example/stl/include/ops_stl.hpp"
22

3+
#include <atomic>
34
#include <cmath>
45
#include <cstddef>
56
#include <functional>

tasks/example/tbb/src/ops_tbb.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <tbb/tbb.h>
44

5+
#include <atomic>
56
#include <cmath>
67
#include <core/util/include/util.hpp>
78
#include <cstddef>
@@ -39,7 +40,7 @@ bool NesterovATestTaskTBB::RunImpl() {
3940
GetOutput() *= num_threads;
4041

4142
std::atomic<int> counter(0);
42-
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int i) { counter++; });
43+
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; });
4344

4445
GetOutput() /= counter;
4546
return GetOutput() > 0;

0 commit comments

Comments
 (0)