GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/linear/parallelmatrixadapter.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 29 33 87.9%
Functions: 100 152 65.8%
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 2289 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4578 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 2289 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2289 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2290 : 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 76072 void apply (const X& x, Y& y) const override
47 {
48 76072 y = 0.0;
49
50 76072 auto& A = this->getmat();
51 using namespace Dune::Hybrid;
52 76072 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 18357978840 Dumux::parallelFor(mat.N(), [&](const std::size_t ii)
61 {
62 1609467922 const auto& row = mat[ii];
63 1609467922 const auto endj = row.end();
64
16/16
✓ Branch 0 taken 292717437 times.
✓ Branch 1 taken 94554115 times.
✓ Branch 2 taken 292717437 times.
✓ Branch 3 taken 94554115 times.
✓ Branch 4 taken 228503893 times.
✓ Branch 5 taken 94503716 times.
✓ Branch 6 taken 228503893 times.
✓ Branch 7 taken 94503716 times.
✓ Branch 8 taken 325172846 times.
✓ Branch 9 taken 709930346 times.
✓ Branch 10 taken 325172846 times.
✓ Branch 11 taken 709930346 times.
✓ Branch 12 taken 5113659400 times.
✓ Branch 13 taken 710479745 times.
✓ Branch 14 taken 5113659400 times.
✓ Branch 15 taken 710479745 times.
13529575074 for (auto jj=row.begin(); jj!=endj; ++jj)
65 {
66 11920107152 const auto& xj = Dune::Impl::asVector(xx[jj.index()]);
67 5960053576 auto&& yi = Dune::Impl::asVector(yy[ii]);
68 17880160728 Dune::Impl::asMatrix(*jj).umv(xj, yi);
69 }
70 });
71 });
72 });
73 76072 }
74
75 //! apply operator to x, scale and add: \f$ y = y + \alpha A(x) \f$
76 2389 void applyscaleadd (field_type alpha, const X& x, Y& y) const override
77 {
78 2389 auto& A = this->getmat();
79 using namespace Dune::Hybrid;
80 21501 forEach(integralRange(Dune::Hybrid::size(y)), [&](auto&& i)
81 {
82 38224 forEach(integralRange(Dune::Hybrid::size(x)), [&](auto&& j)
83 {
84 19112 const auto& mat = A[i][j];
85 9556 const auto& xx = x[j];
86 9556 auto& yy = y[i];
87
88 318651864 Dumux::parallelFor(mat.N(), [&](const std::size_t ii)
89 {
90 20289326 const auto& row = mat[ii];
91 20289326 const auto endj = row.end();
92
16/16
✓ Branch 0 taken 3464767 times.
✓ Branch 1 taken 1184151 times.
✓ Branch 2 taken 3464767 times.
✓ Branch 3 taken 1184151 times.
✓ Branch 4 taken 2071642 times.
✓ Branch 5 taken 1133651 times.
✓ Branch 6 taken 2071642 times.
✓ Branch 7 taken 1133651 times.
✓ Branch 8 taken 3438289 times.
✓ Branch 9 taken 8710512 times.
✓ Branch 10 taken 3438289 times.
✓ Branch 11 taken 8710512 times.
✓ Branch 12 taken 50396553 times.
✓ Branch 13 taken 9261012 times.
✓ Branch 14 taken 50396553 times.
✓ Branch 15 taken 9261012 times.
139031828 for (auto jj=row.begin(); jj!=endj; ++jj)
93 {
94 118742502 const auto& xj = Dune::Impl::asVector(xx[jj.index()]);
95 59371251 auto&& yi = Dune::Impl::asVector(yy[ii]);
96 178118531 Dune::Impl::asMatrix(*jj).usmv(alpha, xj, yi);
97 }
98 });
99 });
100 });
101 2389 }
102 };
103
104 } // end namespace Dumux
105
106 #endif
107