GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/linear/parallelmatrixadapter.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 29 33 87.9%
Functions: 120 148 81.1%
Branches: 36 41 87.8%

Line Branch Exec Source
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 //
4 // SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup Linear
10 * \brief A parallel version of a linear operator
11 */
12 #ifndef DUMUX_LINEAR_PARALLEL_MATRIX_ADAPTER_HH
13 #define DUMUX_LINEAR_PARALLEL_MATRIX_ADAPTER_HH
14
15 #include <dune/common/hybridutilities.hh>
16 #include <dune/istl/operators.hh>
17 #include <dune/istl/bcrsmatrix.hh>
18 #include <dumux/parallel/parallel_for.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \brief Adapter to turn a multi-type matrix into a thread-parallel linear operator.
24 * Adapts a matrix to the assembled linear operator interface
25 */
26 template<class M, class X, class Y>
27
1/4
✓ Branch 0 taken 2844 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
5688 class ParallelMultiTypeMatrixAdapter : public Dune::MatrixAdapter<M,X,Y>
28 {
29 using ParentType = Dune::MatrixAdapter<M,X,Y>;
30 public:
31 //! export types
32 typedef M matrix_type;
33 typedef X domain_type;
34 typedef Y range_type;
35 typedef typename X::field_type field_type;
36
37 //! constructor: just store a reference to a matrix
38 explicit ParallelMultiTypeMatrixAdapter (const M& A)
39
3/5
✓ Branch 1 taken 2844 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2844 times.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
2847 : ParentType(A) {}
40
41 //! constructor: store an std::shared_ptr to a matrix
42 explicit ParallelMultiTypeMatrixAdapter (std::shared_ptr<const M> A)
43 : ParentType(A) {}
44
45 //! apply operator to x: \f$ y = A(x) \f$
46 161055 void apply (const X& x, Y& y) const override
47 {
48 161055 y = 0.0;
49
50 161055 auto& A = this->getmat();
51 using namespace Dune::Hybrid;
52 161055 forEach(integralRange(Dune::Hybrid::size(y)), [&](auto&& i)
53 {
54 forEach(integralRange(Dune::Hybrid::size(x)), [&](auto&& j)
55 {
56 const auto& mat = A[i][j];
57 const auto& xx = x[j];
58 auto& yy = y[i];
59
60 35105804002 Dumux::parallelFor(mat.N(), [&](const std::size_t ii)
61 {
62 3140477176 const auto& row = mat[ii];
63 3140477176 const auto endj = row.end();
64
16/16
✓ Branch 0 taken 625823936 times.
✓ Branch 1 taken 198657216 times.
✓ Branch 2 taken 625823936 times.
✓ Branch 3 taken 198657216 times.
✓ Branch 4 taken 376980375 times.
✓ Branch 5 taken 198606817 times.
✓ Branch 6 taken 376980375 times.
✓ Branch 7 taken 198606817 times.
✓ Branch 8 taken 709991977 times.
✓ Branch 9 taken 1371331872 times.
✓ Branch 10 taken 709991977 times.
✓ Branch 11 taken 1371331872 times.
✓ Branch 12 taken 9559151361 times.
✓ Branch 13 taken 1371881271 times.
✓ Branch 14 taken 9559151361 times.
✓ Branch 15 taken 1371881271 times.
25684372474 for (auto jj=row.begin(); jj!=endj; ++jj)
65 {
66 22543895298 const auto& xj = Dune::Impl::asVector(xx[jj.index()]);
67 11271947649 auto&& yi = Dune::Impl::asVector(yy[ii]);
68 33815842947 Dune::Impl::asMatrix(*jj).umv(xj, yi);
69 }
70 });
71 });
72 });
73 161055 }
74
75 //! apply operator to x, scale and add: \f$ y = y + \alpha A(x) \f$
76 2946 void applyscaleadd (field_type alpha, const X& x, Y& y) const override
77 {
78 2946 auto& A = this->getmat();
79 using namespace Dune::Hybrid;
80 26514 forEach(integralRange(Dune::Hybrid::size(y)), [&](auto&& i)
81 {
82 47136 forEach(integralRange(Dune::Hybrid::size(x)), [&](auto&& j)
83 {
84 23568 const auto& mat = A[i][j];
85 11784 const auto& xx = x[j];
86 11784 auto& yy = y[i];
87
88 499053352 Dumux::parallelFor(mat.N(), [&](const std::size_t ii)
89 {
90 30375404 const auto& row = mat[ii];
91 30375404 const auto endj = row.end();
92
16/16
✓ Branch 0 taken 5693538 times.
✓ Branch 1 taken 1877264 times.
✓ Branch 2 taken 5693538 times.
✓ Branch 3 taken 1877264 times.
✓ Branch 4 taken 3085266 times.
✓ Branch 5 taken 1826764 times.
✓ Branch 6 taken 3085266 times.
✓ Branch 7 taken 1826764 times.
✓ Branch 8 taken 5999808 times.
✓ Branch 9 taken 13060438 times.
✓ Branch 10 taken 5999808 times.
✓ Branch 11 taken 13060438 times.
✓ Branch 12 taken 79606376 times.
✓ Branch 13 taken 13610938 times.
✓ Branch 14 taken 79606376 times.
✓ Branch 15 taken 13610938 times.
219145380 for (auto jj=row.begin(); jj!=endj; ++jj)
93 {
94 188769976 const auto& xj = Dune::Impl::asVector(xx[jj.index()]);
95 94384988 auto&& yi = Dune::Impl::asVector(yy[ii]);
96 283160856 Dune::Impl::asMatrix(*jj).usmv(alpha, xj, yi);
97 }
98 });
99 });
100 });
101 2946 }
102 };
103
104 } // end namespace Dumux
105
106 #endif
107