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