forked from learning-process/parallel_programming_course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathops_seq.cpp
More file actions
58 lines (45 loc) · 1.34 KB
/
ops_seq.cpp
File metadata and controls
58 lines (45 loc) · 1.34 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
54
55
56
57
58
#include "example_processes/seq/include/ops_seq.hpp"
#include <numeric>
#include <vector>
#include "core/util/include/util.hpp"
#include "example_processes/common/include/common.hpp"
namespace nesterov_a_test_task_processes {
NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType& in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = 0;
}
bool NesterovATestTaskSEQ::ValidationImpl() { return (GetInput() > 0) && (GetOutput() == 0); }
bool NesterovATestTaskSEQ::PreProcessingImpl() {
GetOutput() = 2 * GetInput();
return GetOutput() > 0;
}
bool NesterovATestTaskSEQ::RunImpl() {
if (GetInput() == 0) {
return false;
}
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;
int counter = 0;
for (int i = 0; i < num_threads; i++) {
counter++;
}
if (counter != 0) {
GetOutput() /= counter;
}
return GetOutput() > 0;
}
bool NesterovATestTaskSEQ::PostProcessingImpl() {
GetOutput() -= GetInput();
return GetOutput() > 0;
}
} // namespace nesterov_a_test_task_processes