FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
product_matmat_generic.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7#ifndef KERNEL_LAFEM_ARCH_PRODUCT_MATMAT_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_PRODUCT_MATMAT_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_PRODUCT_MATMAT_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
14#include <kernel/util/math.hpp>
15
16#include <iostream>
17
18namespace FEAT
19{
20 namespace LAFEM
21 {
22 namespace Arch
23 {
24 template <typename DT_>
25 void ProductMatMat::dense_generic(DT_ * r, const DT_ alpha, const DT_ beta, const DT_ * const x, const DT_ * const y, const DT_ * const z, const Index rows, const Index columns, const Index inner)
26 {
27 if (Math::abs(beta) < Math::eps<DT_>())
28 {
29 FEAT_PRAGMA_OMP(parallel for)
30 for (Index i = 0 ; i < rows ; ++i)
31 {
32 for (Index j = 0 ; j < columns ; ++j)
33 {
34 DT_ sum(0.);
35 Index xindex(i * inner);
36 Index yindex(j);
37 for (Index xcol(0) ; xcol < inner ; ++xcol)
38 {
39 sum = sum + x[xindex + xcol] * y[yindex + xcol * columns];
40 }
41 r[i * columns + j] = alpha * sum;
42 }
43 }
44 }
45 else
46 {
47 FEAT_PRAGMA_OMP(parallel for)
48 for (Index i = 0 ; i < rows ; ++i)
49 {
50 for (Index j = 0 ; j < columns ; ++j)
51 {
52 DT_ sum(0.);
53 Index xindex(i * inner);
54 Index yindex(j);
55 for (Index xcol(0) ; xcol < inner ; ++xcol)
56 {
57 sum = sum + x[xindex + xcol] * y[yindex + xcol * columns];
58 }
59 r[i * columns + j] = beta * z[i * columns + j] + alpha * sum;
60 }
61 }
62 }
63 }
64
65 template <typename DT_, typename IT_>
66 void ProductMatMat::dsd_generic(DT_ * r, const DT_ alpha, const DT_ beta, const DT_ * const val, const IT_ * const col_ind, const IT_ * const row_ptr, const Index /*used_elements*/,
67 const DT_ * const y, const Index rows, const Index columns, const Index /*inner*/)
68 {
69 if (Math::abs(beta) < Math::eps<DT_>())
70 {
71 FEAT_PRAGMA_OMP(parallel for)
72 for (Index i = 0 ; i < rows ; ++i)
73 {
74 for (Index j = 0 ; j < columns ; ++j)
75 {
76 DT_ sum(0.);
77 Index xindex = row_ptr[i];
78 Index yindex(j);
79 for (Index tmp = xindex ; tmp < row_ptr[i+1] ; ++tmp)
80 {
81 sum = sum + val[tmp] * y[yindex + col_ind[tmp] * columns];
82 }
83 r[i * columns + j] = alpha * sum;
84 }
85 }
86 }
87 else
88 {
89 FEAT_PRAGMA_OMP(parallel for)
90 for (Index i = 0 ; i < rows ; ++i)
91 {
92 for (Index j = 0 ; j < columns ; ++j)
93 {
94 DT_ sum(0.);
95 Index xindex = row_ptr[i];
96 Index yindex(j);
97 for (Index tmp = xindex ; tmp < row_ptr[i+1] ; ++tmp)
98 {
99 sum = sum + val[tmp] * y[yindex + col_ind[tmp] * columns];
100 }
101 r[i * columns + j] = beta * r[i * columns + j] + alpha * sum;
102 }
103 }
104 }
105 }
106 } // namespace Arch
107 } // namespace LAFEM
108} // namespace FEAT
109
110#endif // KERNEL_LAFEM_ARCH_PRODUCT_MATMAT_GENERIC_HPP
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.