forked from learning-process/parallel_programming_course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathops_stl.cpp
More file actions
47 lines (39 loc) · 1.41 KB
/
ops_stl.cpp
File metadata and controls
47 lines (39 loc) · 1.41 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
#include "stl/example/include/ops_stl.hpp"
#include <cmath>
#include <cstddef>
#include <functional>
#include <thread>
#include <vector>
#include "core/util/include/util.hpp"
namespace {
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
for (int i = 0; i < rc_size; ++i) {
for (int j = 0; j < rc_size; ++j) {
out_vec[(i * rc_size) + j] = 0;
for (int k = 0; k < rc_size; ++k) {
out_vec[(i * rc_size) + j] += in_vec[(i * rc_size) + k] * in_vec[(k * rc_size) + j];
}
}
}
}
} // namespace
bool nesterov_a_test_task_stl::TestTaskSTL::ValidationImpl() {
auto sqrt_size = static_cast<int>(std::sqrt(input_.size()));
return sqrt_size * sqrt_size == static_cast<int>(input_.size());
}
bool nesterov_a_test_task_stl::TestTaskSTL::PreProcessingImpl() {
rc_size_ = static_cast<int>(std::sqrt(input_.size()));
output_ = std::vector<int>(input_.size(), 0);
return true;
}
bool nesterov_a_test_task_stl::TestTaskSTL::RunImpl() {
const int num_threads = ppc::util::GetNumThreads();
std::vector<std::thread> threads(num_threads);
for (int i = 0; i < num_threads; i++) {
threads[i] = std::thread(MatMul, std::cref(input_), rc_size_, std::ref(output_));
threads[i].join();
}
return true;
}
bool nesterov_a_test_task_stl::TestTaskSTL::PostProcessingImpl() { return true; }
std::vector<int> nesterov_a_test_task_stl::TestTaskSTL::Get() { return output_; }