Skip to content

Commit a8f66aa

Browse files
committed
fix reduction
1 parent 46a7d58 commit a8f66aa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tasks/example_threads/omp/src/ops_omp.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ bool NesterovATestTaskOMP::RunImpl() {
3636
const int num_threads = ppc::util::GetNumThreads();
3737
GetOutput() *= num_threads;
3838

39-
std::atomic<int> counter(0);
40-
#pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads())
41-
counter++;
39+
std::atomic<int> counter{0};
40+
#pragma omp parallel default(none) shared(counter) num_threads(num_threads)
41+
{
42+
counter.fetch_add(1, std::memory_order_relaxed);
43+
}
4244

43-
GetOutput() /= counter;
45+
GetOutput() /= counter.load(std::memory_order_relaxed);
4446
return GetOutput() > 0;
4547
}
4648

0 commit comments

Comments
 (0)