GCC Code Coverage Report


Directory: ./
File: tasks/afanasyev_a_integ_rect_method/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 6 6 100.0%
Branches: 3 4 75.0%

Line Branch Exec Source
1 #include "afanasyev_a_integ_rect_method/omp/include/ops_omp.hpp"
2
3 #include <cmath>
4 #include <vector>
5
6 #include "afanasyev_a_integ_rect_method/common/include/common.hpp"
7
8 namespace afanasyev_a_integ_rect_method {
9 namespace {
10
11 2160000 double ExampleIntegrand(const std::vector<double> &x) {
12 double s = 0.0;
13
2/2
✓ Branch 0 taken 6480000 times.
✓ Branch 1 taken 2160000 times.
8640000 for (double xi : x) {
14 6480000 s += xi * xi;
15 }
16 2160000 return std::exp(-s);
17 }
18
19 } // namespace
20
21 12 AfanasyevAIntegRectMethodOMP::AfanasyevAIntegRectMethodOMP(const InType &in) {
22 SetTypeOfTask(GetStaticTypeOfTask());
23 12 GetInput() = in;
24 GetOutput() = 0.0;
25 12 }
26
27 12 bool AfanasyevAIntegRectMethodOMP::ValidationImpl() {
28 12 return (GetInput() > 0);
29 }
30
31 12 bool AfanasyevAIntegRectMethodOMP::PreProcessingImpl() {
32 12 return true;
33 }
34
35 12 bool AfanasyevAIntegRectMethodOMP::RunImpl() {
36 12 const int n = GetInput();
37
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (n <= 0) {
38 return false;
39 }
40
41 const int k_dim = 3;
42
43 12 const double h = 1.0 / static_cast<double>(n);
44
45 double sum = 0.0;
46
47 12 #pragma omp parallel for collapse(3) reduction(+ : sum) default(none) shared(n, h, k_dim)
48 for (int i = 0; i < n; ++i) {
49 for (int j = 0; j < n; ++j) {
50 for (int k = 0; k < n; ++k) {
51 std::vector<double> x = {(static_cast<double>(i) + 0.5) * h, (static_cast<double>(j) + 0.5) * h,
52 (static_cast<double>(k) + 0.5) * h};
53 sum += ExampleIntegrand(x);
54 }
55 }
56 }
57
58 const double volume = std::pow(h, k_dim);
59 12 GetOutput() = sum * volume;
60
61 12 return true;
62 }
63
64 12 bool AfanasyevAIntegRectMethodOMP::PostProcessingImpl() {
65 12 return true;
66 }
67
68 } // namespace afanasyev_a_integ_rect_method
69