| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ovsyannikov_n_simpson_method/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <functional> | ||
| 7 | |||
| 8 | #include "ovsyannikov_n_simpson_method/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace ovsyannikov_n_simpson_method { | ||
| 11 | |||
| 12 | ✗ | double OvsyannikovNSimpsonMethodTBB::Function(double x, double y) { | |
| 13 | 34224 | return x + y; | |
| 14 | } | ||
| 15 | |||
| 16 | ✗ | double OvsyannikovNSimpsonMethodTBB::GetCoeff(int i, int n) { | |
| 17 | ✗ | if (i == 0 || i == n) { | |
| 18 | return 1.0; | ||
| 19 | } | ||
| 20 |
4/6✓ Branch 0 taken 376 times.
✓ Branch 1 taken 400 times.
✓ Branch 2 taken 15876 times.
✓ Branch 3 taken 16700 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
33352 | return (i % 2 == 1) ? 4.0 : 2.0; |
| 21 | } | ||
| 22 | |||
| 23 | 24 | OvsyannikovNSimpsonMethodTBB::OvsyannikovNSimpsonMethodTBB(const InType &in) { | |
| 24 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 25 | 24 | GetInput() = in; | |
| 26 | 24 | } | |
| 27 | |||
| 28 | 24 | bool OvsyannikovNSimpsonMethodTBB::ValidationImpl() { | |
| 29 |
4/8✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 24 times.
|
24 | return GetInput().nx > 0 && GetInput().nx % 2 == 0 && GetInput().ny > 0 && GetInput().ny % 2 == 0; |
| 30 | } | ||
| 31 | |||
| 32 | 24 | bool OvsyannikovNSimpsonMethodTBB::PreProcessingImpl() { | |
| 33 | 24 | params_ = GetInput(); | |
| 34 | 24 | res_ = 0.0; | |
| 35 | 24 | return true; | |
| 36 | } | ||
| 37 | |||
| 38 | 24 | bool OvsyannikovNSimpsonMethodTBB::RunImpl() { | |
| 39 | 24 | const int nx_l = params_.nx; | |
| 40 | 24 | const int ny_l = params_.ny; | |
| 41 | 24 | const double ax_l = params_.ax; | |
| 42 | 24 | const double ay_l = params_.ay; | |
| 43 | 24 | const double hx = (params_.bx - params_.ax) / nx_l; | |
| 44 | 24 | const double hy = (params_.by - params_.ay) / ny_l; | |
| 45 | |||
| 46 | 48 | double total_sum = tbb::parallel_reduce(tbb::blocked_range<int>(0, nx_l + 1), 0.0, | |
| 47 | 848 | [&](const tbb::blocked_range<int> &r, double local_sum) { | |
| 48 |
2/2✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
|
1648 | for (int i = r.begin(); i < r.end(); ++i) { |
| 49 | 824 | const double x = ax_l + (i * hx); | |
| 50 |
2/2✓ Branch 0 taken 776 times.
✓ Branch 1 taken 48 times.
|
824 | const double coeff_x = GetCoeff(i, nx_l); |
| 51 | double row_sum = 0.0; | ||
| 52 |
2/2✓ Branch 0 taken 34224 times.
✓ Branch 1 taken 824 times.
|
35048 | for (int j = 0; j <= ny_l; ++j) { |
| 53 |
2/2✓ Branch 0 taken 32576 times.
✓ Branch 1 taken 1648 times.
|
34224 | const double y = ay_l + (j * hy); |
| 54 | const double coeff_y = GetCoeff(j, ny_l); | ||
| 55 | 34224 | row_sum += coeff_y * Function(x, y); | |
| 56 | } | ||
| 57 | 824 | local_sum += coeff_x * row_sum; | |
| 58 | } | ||
| 59 | 824 | return local_sum; | |
| 60 | 24 | }, std::plus<>()); | |
| 61 | |||
| 62 | 24 | res_ = (hx * hy / 9.0) * total_sum; | |
| 63 | 24 | return true; | |
| 64 | } | ||
| 65 | |||
| 66 | 24 | bool OvsyannikovNSimpsonMethodTBB::PostProcessingImpl() { | |
| 67 | 24 | GetOutput() = res_; | |
| 68 | 24 | return true; | |
| 69 | } | ||
| 70 | } // namespace ovsyannikov_n_simpson_method | ||
| 71 |