Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Csr/OpenMP/Morpheus_Convert_Impl.hpp
1
24#ifndef MORPHEUS_CSR_OPENMP_CONVERT_IMPL_HPP
25#define MORPHEUS_CSR_OPENMP_CONVERT_IMPL_HPP
26
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_OPENMP)
29
30#include <Morpheus_Exceptions.hpp>
31#include <Morpheus_SpaceTraits.hpp>
32#include <Morpheus_FormatTraits.hpp>
33#include <Morpheus_FormatTags.hpp>
34#include <Morpheus_Spaces.hpp>
35
36namespace Morpheus {
37namespace Impl {
38
39template <typename ExecSpace, typename SourceType, typename DestinationType>
40void convert(
41 const SourceType& src, DestinationType& dst,
42 typename std::enable_if<
43 Morpheus::is_csr_matrix_format_container_v<SourceType> &&
44 Morpheus::is_csr_matrix_format_container_v<DestinationType> &&
45 Morpheus::has_custom_backend_v<ExecSpace> &&
46 Morpheus::has_openmp_execution_space_v<ExecSpace> &&
47 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
48 nullptr) {
49 using size_type = typename SourceType::size_type;
50
51 dst.resize(src.nrows(), src.ncols(), src.nnnz());
52
53// element-wise copy of indices and values
54#pragma omp parallel for
55 for (size_type n = 0; n < src.nrows() + 1; n++) {
56 dst.row_offsets(n) = src.crow_offsets(n);
57 }
58
59#pragma omp parallel for
60 for (size_type n = 0; n < src.nnnz(); n++) {
61 dst.column_indices(n) = src.ccolumn_indices(n);
62 }
63
64#pragma omp parallel for
65 for (size_type n = 0; n < src.nnnz(); n++) {
66 dst.values(n) = src.cvalues(n);
67 }
68}
69
70template <typename ExecSpace, typename SourceType, typename DestinationType>
71void convert(
72 const SourceType& src, DestinationType& dst,
73 typename std::enable_if<
74 Morpheus::is_csr_matrix_format_container_v<SourceType> &&
75 Morpheus::is_coo_matrix_format_container_v<DestinationType> &&
76 Morpheus::has_custom_backend_v<ExecSpace> &&
77 Morpheus::has_openmp_execution_space_v<ExecSpace> &&
78 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
79 nullptr) {
80 using size_type = typename SourceType::size_type;
81 using index_type = typename SourceType::index_type;
82
83 dst.resize(src.nrows(), src.ncols(), src.nnnz());
84
85// expand compressed indices
86#pragma omp parallel for
87 for (size_type i = 0; i < src.nrows(); i++) {
88 for (index_type jj = src.crow_offsets(i); jj < src.crow_offsets(i + 1);
89 jj++) {
90 dst.row_indices(jj) = i;
91 }
92 }
93
94#pragma omp parallel for
95 for (size_type n = 0; n < src.nnnz(); n++) {
96 dst.column_indices(n) = src.ccolumn_indices(n);
97 }
98
99#pragma omp parallel for
100 for (size_type n = 0; n < src.nnnz(); n++) {
101 dst.values(n) = src.cvalues(n);
102 }
103}
104
105template <typename ExecSpace, typename SourceType, typename DestinationType>
106void convert(
107 const SourceType&, DestinationType&,
108 typename std::enable_if<
109 Morpheus::is_coo_matrix_format_container_v<SourceType> &&
110 Morpheus::is_csr_matrix_format_container_v<DestinationType> &&
111 Morpheus::has_custom_backend_v<ExecSpace> &&
112 Morpheus::has_openmp_execution_space_v<ExecSpace> &&
113 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
114 nullptr) {
115 throw Morpheus::NotImplementedException("convert<Kokkos::OpenMP>");
116}
117
118} // namespace Impl
119} // namespace Morpheus
120
121#endif // MORPHEUS_ENABLE_OPENMP
122#endif // MORPHEUS_CSR_OPENMP_CONVERT_IMPL_HPP
Definition: Morpheus_Exceptions.hpp:43
Generic Morpheus interfaces.
Definition: dummy.cpp:24