Skip to content

Commit 92d7b85

Browse files
committed
Refactor OpenMP thread handling and remove redundant omp_set_num_threads calls
Updated `#pragma omp parallel` statements to explicitly define `num_threads` using `ppc::util::GetNumThreads()`. Removed redundant `omp_set_num_threads` calls in runners, streamlining thread configuration across the codebase.
1 parent 110cd96 commit 92d7b85

5 files changed

Lines changed: 3 additions & 9 deletions

File tree

tasks/common/runners/functional.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ int main(int argc, char** argv) {
7676

7777
// Limit the number of threads in TBB
7878
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
79-
// Limit the number of threads in OMP
80-
omp_set_num_threads(ppc::util::GetNumThreads());
8179

8280
::testing::InitGoogleTest(&argc, argv);
8381

@@ -97,8 +95,6 @@ int main(int argc, char** argv) {
9795

9896
// Limit the number of threads in TBB
9997
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
100-
// Limit the number of threads in OMP
101-
omp_set_num_threads(ppc::util::GetNumThreads());
10298

10399
::testing::InitGoogleTest(&argc, argv);
104100
return RUN_ALL_TESTS();

tasks/common/runners/performance.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ int main(int argc, char** argv) {
7575

7676
// Limit the number of threads in TBB
7777
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
78-
// Limit the number of threads in OMP
79-
omp_set_num_threads(ppc::util::GetNumThreads());
8078

8179
::testing::InitGoogleTest(&argc, argv);
8280

tasks/common/tests/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TEST(ppc_func_tests_common, threads_control_check_openmp) {
1313
int ppc_num_threads = ppc::util::GetNumThreads();
1414

1515
int omp_num_threads = -1;
16-
#pragma omp parallel default(none) shared(omp_num_threads)
16+
#pragma omp parallel default(none) shared(omp_num_threads) num_threads(ppc::util::GetNumThreads())
1717
omp_num_threads = omp_get_num_threads();
1818

1919
// Check Result

tasks/example/all/src/ops_all.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool NesterovATestTaskALL::RunImpl() {
4646
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4747
if (rank == 0) {
4848
std::atomic<int> counter(0);
49-
#pragma omp parallel default(none) shared(counter)
49+
#pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads())
5050
counter++;
5151

5252
GetOutput() /= counter;

tasks/example/omp/src/ops_omp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool NesterovATestTaskOMP::RunImpl() {
3535
GetOutput() *= num_threads;
3636

3737
std::atomic<int> counter(0);
38-
#pragma omp parallel default(none) shared(counter)
38+
#pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads())
3939
counter++;
4040

4141
GetOutput() /= counter;

0 commit comments

Comments
 (0)