Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "example_threads/all/include/ops_all.hpp" | ||
2 | |||
3 | #include <mpi.h> | ||
4 | |||
5 | #include <atomic> | ||
6 | #include <numeric> | ||
7 | #include <thread> | ||
8 | #include <vector> | ||
9 | |||
10 | #include "example_threads/common/include/common.hpp" | ||
11 | #include "oneapi/tbb/parallel_for.h" | ||
12 | #include "util/include/util.hpp" | ||
13 | |||
14 | namespace nesterov_a_test_task_threads { | ||
15 | |||
16 | 60 | NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) { | |
17 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
18 | 60 | GetInput() = in; | |
19 | GetOutput() = 0; | ||
20 | 60 | } | |
21 | |||
22 | 60 | bool NesterovATestTaskALL::ValidationImpl() { | |
23 |
2/4✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 60 times.
|
60 | return (GetInput() > 0) && (GetOutput() == 0); |
24 | } | ||
25 | |||
26 | 60 | bool NesterovATestTaskALL::PreProcessingImpl() { | |
27 | 60 | GetOutput() = 2 * GetInput(); | |
28 | 60 | return GetOutput() > 0; | |
29 | } | ||
30 | |||
31 | 60 | bool NesterovATestTaskALL::RunImpl() { | |
32 |
2/2✓ Branch 0 taken 180 times.
✓ Branch 1 taken 60 times.
|
240 | for (InType i = 0; i < GetInput(); i++) { |
33 |
2/2✓ Branch 0 taken 540 times.
✓ Branch 1 taken 180 times.
|
720 | for (InType j = 0; j < GetInput(); j++) { |
34 |
2/2✓ Branch 0 taken 1620 times.
✓ Branch 1 taken 540 times.
|
2160 | for (InType k = 0; k < GetInput(); k++) { |
35 | 1620 | std::vector<InType> tmp(i + j + k, 1); | |
36 | 1620 | GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); | |
37 |
2/2✓ Branch 0 taken 1560 times.
✓ Branch 1 taken 60 times.
|
1620 | GetOutput() -= i + j + k; |
38 | } | ||
39 | } | ||
40 | } | ||
41 | |||
42 | 60 | const int num_threads = ppc::util::GetNumThreads(); | |
43 | { | ||
44 | 60 | GetOutput() *= num_threads; | |
45 | |||
46 | 60 | int rank = -1; | |
47 | 60 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
48 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
|
60 | if (rank == 0) { |
49 | 30 | std::atomic<int> counter(0); | |
50 | 30 | #pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads()) | |
51 | counter++; | ||
52 | |||
53 | 30 | GetOutput() /= counter; | |
54 | } else { | ||
55 | 30 | GetOutput() /= num_threads; | |
56 | } | ||
57 | } | ||
58 | |||
59 | { | ||
60 | 60 | GetOutput() *= num_threads; | |
61 | 60 | std::vector<std::thread> threads(num_threads); | |
62 | 60 | std::atomic<int> counter(0); | |
63 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 60 times.
|
180 | for (int i = 0; i < num_threads; i++) { |
64 |
2/4✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 120 times.
|
120 | threads[i] = std::thread([&]() { counter++; }); |
65 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | threads[i].join(); |
66 | } | ||
67 | 60 | GetOutput() /= counter; | |
68 | 60 | } | |
69 | |||
70 | { | ||
71 | 60 | GetOutput() *= num_threads; | |
72 | 60 | std::atomic<int> counter(0); | |
73 | 240 | tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; }); | |
74 | 60 | GetOutput() /= counter; | |
75 | } | ||
76 | 60 | MPI_Barrier(MPI_COMM_WORLD); | |
77 | 60 | return GetOutput() > 0; | |
78 | } | ||
79 | |||
80 | 60 | bool NesterovATestTaskALL::PostProcessingImpl() { | |
81 | 60 | GetOutput() -= GetInput(); | |
82 | 60 | return GetOutput() > 0; | |
83 | } | ||
84 | |||
85 | } // namespace nesterov_a_test_task_threads | ||
86 |