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