-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathops_omp.cpp
More file actions
53 lines (41 loc) · 1.35 KB
/
ops_omp.cpp
File metadata and controls
53 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "example_threads/omp/include/ops_omp.hpp"
#include <atomic>
#include <numeric>
#include <vector>
#include <omp.h>
#include "core/util/include/util.hpp"
#include "example_threads/common/include/common.hpp"
namespace nesterov_a_test_task_threads {
NesterovATestTaskOMP::NesterovATestTaskOMP(const InType& in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = 0;
}
bool NesterovATestTaskOMP::ValidationImpl() { return (GetInput() > 0) && (GetOutput() == 0); }
bool NesterovATestTaskOMP::PreProcessingImpl() {
GetOutput() = 2 * GetInput();
return GetOutput() > 0;
}
bool NesterovATestTaskOMP::RunImpl() {
for (InType i = 0; i < GetInput(); i++) {
for (InType j = 0; j < GetInput(); j++) {
for (InType k = 0; k < GetInput(); k++) {
std::vector<InType> tmp(i + j + k, 1);
GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0);
GetOutput() -= i + j + k;
}
}
}
const int num_threads = ppc::util::GetNumThreads();
GetOutput() *= num_threads;
std::atomic<int> counter(0);
#pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads())
counter++;
GetOutput() /= counter;
return GetOutput() > 0;
}
bool NesterovATestTaskOMP::PostProcessingImpl() {
GetOutput() -= GetInput();
return GetOutput() > 0;
}
} // namespace nesterov_a_test_task_threads