Skip to content

Commit 2a6f8fc

Browse files
committed
Refactor code to consistently use namespaces.
Unified the usage of the `nesterov_a_test_task` namespace across all files, removing redundant namespace qualifiers and wrapping implementations within the namespace. This enhances readability, consistency, and maintainability of the codebase.
1 parent d8f9a49 commit 2a6f8fc

6 files changed

Lines changed: 58 additions & 35 deletions

File tree

tasks/example/all/src/ops_all.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include "core/util/include/util.hpp"
1212
#include "oneapi/tbb/parallel_for.h"
1313

14-
void nesterov_a_test_task::MatMul(const InType &in_vec, int rc_size, OutType &out_vec) {
14+
namespace nesterov_a_test_task {
15+
16+
void MatMul(const InType &in_vec, int rc_size, OutType &out_vec) {
1517
for (int i = 0; i < rc_size; ++i) {
1618
for (int j = 0; j < rc_size; ++j) {
1719
out_vec[(i * rc_size) + j] = 0;
@@ -22,29 +24,29 @@ void nesterov_a_test_task::MatMul(const InType &in_vec, int rc_size, OutType &ou
2224
}
2325
}
2426

25-
void nesterov_a_test_task::MatMulTBB(const InType &in_vec, int rc_size, OutType &out_vec) {
27+
void MatMulTBB(const InType &in_vec, int rc_size, OutType &out_vec) {
2628
tbb::parallel_for(0, ppc::util::GetPPCNumThreads(), [&](int i) { MatMul(in_vec, rc_size - i, out_vec); });
2729
MatMul(in_vec, rc_size, out_vec);
2830
}
2931

30-
nesterov_a_test_task::NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) {
32+
NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) {
3133
SetTypeOfTask(GetStaticTypeOfTask());
3234
GetInput() = in;
3335
}
3436

35-
bool nesterov_a_test_task::NesterovATestTaskALL::ValidationImpl() {
37+
bool NesterovATestTaskALL::ValidationImpl() {
3638
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
3739
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
3840
}
3941

40-
bool nesterov_a_test_task::NesterovATestTaskALL::PreProcessingImpl() {
42+
bool NesterovATestTaskALL::PreProcessingImpl() {
4143
// Init value for input and output
4244
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
4345
GetOutput() = OutType(GetInput().size(), 0);
4446
return true;
4547
}
4648

47-
bool nesterov_a_test_task::NesterovATestTaskALL::RunImpl() {
49+
bool NesterovATestTaskALL::RunImpl() {
4850
int rank = -1;
4951
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5052
if (rank == 0) {
@@ -68,4 +70,6 @@ bool nesterov_a_test_task::NesterovATestTaskALL::RunImpl() {
6870
return true;
6971
}
7072

71-
bool nesterov_a_test_task::NesterovATestTaskALL::PostProcessingImpl() { return true; }
73+
bool NesterovATestTaskALL::PostProcessingImpl() { return true; }
74+
75+
} // namespace nesterov_a_test_task

tasks/example/mpi/src/ops_mpi.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include <cmath>
66
#include <cstddef>
77
#include <vector>
8+
namespace nesterov_a_test_task {
89

9-
void nesterov_a_test_task::MultiplyRowMajor(const InType &in, OutType &out, int rc_size) {
10+
void MultiplyRowMajor(const InType &in, OutType &out, int rc_size) {
1011
for (int i = 0; i < rc_size; ++i) {
1112
for (int j = 0; j < rc_size; ++j) {
1213
for (int k = 0; k < rc_size; ++k) {
@@ -16,7 +17,7 @@ void nesterov_a_test_task::MultiplyRowMajor(const InType &in, OutType &out, int
1617
}
1718
}
1819

19-
void nesterov_a_test_task::MultiplyColumnMajor(const InType &in, OutType &out, int rc_size) {
20+
void MultiplyColumnMajor(const InType &in, OutType &out, int rc_size) {
2021
for (int j = 0; j < rc_size; ++j) {
2122
for (int k = 0; k < rc_size; ++k) {
2223
for (int i = 0; i < rc_size; ++i) {
@@ -26,31 +27,31 @@ void nesterov_a_test_task::MultiplyColumnMajor(const InType &in, OutType &out, i
2627
}
2728
}
2829

29-
nesterov_a_test_task::NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) {
30+
NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) {
3031
SetTypeOfTask(GetStaticTypeOfTask());
3132
GetInput() = in;
3233
}
3334

34-
bool nesterov_a_test_task::NesterovATestTaskMPI::ValidationImpl() {
35+
bool NesterovATestTaskMPI::ValidationImpl() {
3536
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
3637
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
3738
}
3839

39-
bool nesterov_a_test_task::NesterovATestTaskMPI::PreProcessingImpl() {
40+
bool NesterovATestTaskMPI::PreProcessingImpl() {
4041
// Init value for input and output
4142
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
4243
GetOutput() = OutType(GetInput().size(), 0);
4344
return true;
4445
}
4546

46-
bool nesterov_a_test_task::NesterovATestTaskMPI::RunImpl() {
47+
bool NesterovATestTaskMPI::RunImpl() {
4748
MultiplyMatrixBasedOnRank();
4849
return true;
4950
}
5051

51-
bool nesterov_a_test_task::NesterovATestTaskMPI::PostProcessingImpl() { return true; }
52+
bool NesterovATestTaskMPI::PostProcessingImpl() { return true; }
5253

53-
void nesterov_a_test_task::NesterovATestTaskMPI::MultiplyMatrixBasedOnRank() {
54+
void NesterovATestTaskMPI::MultiplyMatrixBasedOnRank() {
5455
int rank = -1;
5556
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5657

@@ -61,3 +62,5 @@ void nesterov_a_test_task::NesterovATestTaskMPI::MultiplyMatrixBasedOnRank() {
6162
}
6263
MPI_Barrier(MPI_COMM_WORLD);
6364
}
65+
66+
} // namespace nesterov_a_test_task

tasks/example/omp/src/ops_omp.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
#include <cstddef>
55
#include <vector>
66

7-
nesterov_a_test_task::NesterovATestTaskOMP::NesterovATestTaskOMP(const InType& in) {
7+
namespace nesterov_a_test_task {
8+
9+
NesterovATestTaskOMP::NesterovATestTaskOMP(const InType& in) {
810
SetTypeOfTask(GetStaticTypeOfTask());
911
GetInput() = in;
1012
}
1113

12-
bool nesterov_a_test_task::NesterovATestTaskOMP::ValidationImpl() {
14+
bool NesterovATestTaskOMP::ValidationImpl() {
1315
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
1416
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
1517
}
1618

17-
bool nesterov_a_test_task::NesterovATestTaskOMP::PreProcessingImpl() {
19+
bool NesterovATestTaskOMP::PreProcessingImpl() {
1820
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
1921
GetOutput() = OutType(GetInput().size(), 0);
2022
return true;
2123
}
2224

23-
bool nesterov_a_test_task::NesterovATestTaskOMP::RunImpl() {
25+
bool NesterovATestTaskOMP::RunImpl() {
2426
#pragma omp parallel default(none)
2527
{
2628
#pragma omp critical
@@ -39,4 +41,6 @@ bool nesterov_a_test_task::NesterovATestTaskOMP::RunImpl() {
3941
return true;
4042
}
4143

42-
bool nesterov_a_test_task::NesterovATestTaskOMP::PostProcessingImpl() { return true; }
44+
bool NesterovATestTaskOMP::PostProcessingImpl() { return true; }
45+
46+
} // namespace nesterov_a_test_task

tasks/example/seq/src/ops_seq.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
#include <cstddef>
55
#include <vector>
66

7-
nesterov_a_test_task::NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType& in) {
7+
namespace nesterov_a_test_task {
8+
9+
NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType& in) {
810
SetTypeOfTask(GetStaticTypeOfTask());
911
GetInput() = in;
1012
}
1113

12-
bool nesterov_a_test_task::NesterovATestTaskSEQ::ValidationImpl() {
14+
bool NesterovATestTaskSEQ::ValidationImpl() {
1315
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
1416
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
1517
}
1618

17-
bool nesterov_a_test_task::NesterovATestTaskSEQ::PreProcessingImpl() {
19+
bool NesterovATestTaskSEQ::PreProcessingImpl() {
1820
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
1921
GetOutput() = OutType(GetInput().size(), 0);
2022
return true;
2123
}
2224

23-
bool nesterov_a_test_task::NesterovATestTaskSEQ::RunImpl() {
25+
bool NesterovATestTaskSEQ::RunImpl() {
2426
// Multiply matrices
2527
for (int i = 0; i < rc_size_; ++i) {
2628
for (int j = 0; j < rc_size_; ++j) {
@@ -32,4 +34,6 @@ bool nesterov_a_test_task::NesterovATestTaskSEQ::RunImpl() {
3234
return true;
3335
}
3436

35-
bool nesterov_a_test_task::NesterovATestTaskSEQ::PostProcessingImpl() { return true; }
37+
bool NesterovATestTaskSEQ::PostProcessingImpl() { return true; }
38+
39+
} // namespace nesterov_a_test_task

tasks/example/stl/src/ops_stl.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "core/util/include/util.hpp"
1010

11+
namespace nesterov_a_test_task {
12+
1113
namespace {
1214
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
1315
for (int i = 0; i < rc_size; ++i) {
@@ -21,23 +23,23 @@ void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_v
2123
}
2224
} // namespace
2325

24-
nesterov_a_test_task::NesterovATestTaskSTL::NesterovATestTaskSTL(const InType &in) {
26+
NesterovATestTaskSTL::NesterovATestTaskSTL(const InType &in) {
2527
SetTypeOfTask(GetStaticTypeOfTask());
2628
GetInput() = in;
2729
}
2830

29-
bool nesterov_a_test_task::NesterovATestTaskSTL::ValidationImpl() {
31+
bool NesterovATestTaskSTL::ValidationImpl() {
3032
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
3133
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
3234
}
3335

34-
bool nesterov_a_test_task::NesterovATestTaskSTL::PreProcessingImpl() {
36+
bool NesterovATestTaskSTL::PreProcessingImpl() {
3537
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
3638
GetOutput() = OutType(GetInput().size(), 0);
3739
return true;
3840
}
3941

40-
bool nesterov_a_test_task::NesterovATestTaskSTL::RunImpl() {
42+
bool NesterovATestTaskSTL::RunImpl() {
4143
const int num_threads = ppc::util::GetPPCNumThreads();
4244
std::vector<std::thread> threads(num_threads);
4345
for (int i = 0; i < num_threads; i++) {
@@ -47,4 +49,6 @@ bool nesterov_a_test_task::NesterovATestTaskSTL::RunImpl() {
4749
return true;
4850
}
4951

50-
bool nesterov_a_test_task::NesterovATestTaskSTL::PostProcessingImpl() { return true; }
52+
bool NesterovATestTaskSTL::PostProcessingImpl() { return true; }
53+
54+
} // namespace nesterov_a_test_task

tasks/example/tbb/src/ops_tbb.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "oneapi/tbb/parallel_for.h"
1111

12+
namespace nesterov_a_test_task {
13+
1214
namespace {
1315
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
1416
for (int i = 0; i < rc_size; ++i) {
@@ -22,26 +24,28 @@ void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_v
2224
}
2325
} // namespace
2426

25-
nesterov_a_test_task::NesterovATestTaskTBB::NesterovATestTaskTBB(const InType &in) {
27+
NesterovATestTaskTBB::NesterovATestTaskTBB(const InType &in) {
2628
SetTypeOfTask(GetStaticTypeOfTask());
2729
GetInput() = in;
2830
}
2931

30-
bool nesterov_a_test_task::NesterovATestTaskTBB::ValidationImpl() {
32+
bool NesterovATestTaskTBB::ValidationImpl() {
3133
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
3234
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
3335
}
3436

35-
bool nesterov_a_test_task::NesterovATestTaskTBB::PreProcessingImpl() {
37+
bool NesterovATestTaskTBB::PreProcessingImpl() {
3638
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
3739
GetOutput() = OutType(GetInput().size(), 0);
3840
return true;
3941
}
4042

41-
bool nesterov_a_test_task::NesterovATestTaskTBB::RunImpl() {
43+
bool NesterovATestTaskTBB::RunImpl() {
4244
tbb::parallel_for(0, ppc::util::GetPPCNumThreads(), [&](int i) { MatMul(GetInput(), rc_size_ - i, GetOutput()); });
4345
MatMul(GetInput(), rc_size_, GetOutput());
4446
return true;
4547
}
4648

47-
bool nesterov_a_test_task::NesterovATestTaskTBB::PostProcessingImpl() { return true; }
49+
bool NesterovATestTaskTBB::PostProcessingImpl() { return true; }
50+
51+
} // namespace nesterov_a_test_task

0 commit comments

Comments
 (0)