Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Dia/OpenMP/Morpheus_Multiply_Impl.hpp
1
24#ifndef MORPHEUS_DIA_OPENMP_MULTIPLY_IMPL_HPP
25#define MORPHEUS_DIA_OPENMP_MULTIPLY_IMPL_HPP
26
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_OPENMP)
29
30#include <Morpheus_SpaceTraits.hpp>
31#include <Morpheus_FormatTraits.hpp>
32#include <Morpheus_FormatTags.hpp>
33#include <Morpheus_Spaces.hpp>
34
35namespace Morpheus {
36namespace Impl {
37
38template <typename ExecSpace, typename Matrix, typename Vector>
39inline void multiply(
40 const Matrix& A, const Vector& x, Vector& y, const bool init,
41 typename std::enable_if_t<
42 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
43 Morpheus::is_dense_vector_format_container_v<Vector> &&
44 Morpheus::has_custom_backend_v<ExecSpace> &&
45 Morpheus::has_openmp_execution_space_v<ExecSpace> &&
46 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
47 using size_type = typename Matrix::size_type;
48 using index_type = typename Matrix::index_type;
49 using value_type = typename Matrix::value_type;
50 const size_type ndiag = A.cdiagonal_offsets().size();
51
52#pragma omp parallel for
53 for (size_type row = 0; row < A.nrows(); row++) {
54 value_type sum = init ? value_type(0) : y[row];
55
56 for (size_type n = 0; n < ndiag; n++) {
57 const index_type col = row + A.cdiagonal_offsets(n);
58
59 if (col >= 0 && col < (index_type)A.ncols()) {
60 sum += A.cvalues(row, n) * x[col];
61 }
62 }
63 y[row] = sum;
64 }
65}
66
67} // namespace Impl
68} // namespace Morpheus
69
70#endif // MORPHEUS_ENABLE_OPENMP
71#endif // MORPHEUS_DIA_OPENMP_MULTIPLY_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24