Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_MatrixTraits.hpp
1// @HEADER
2// *****************************************************************************
3// Amesos2: Templated Direct Sparse Solver Package
4//
5// Copyright 2011 NTESS and the Amesos2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10
11#ifndef AMESOS2_MATRIXTRAITS_HPP
12#define AMESOS2_MATRIXTRAITS_HPP
13
14#include "Amesos2_config.h"
15
16#include <Tpetra_CrsMatrix.hpp>
17
18
19#ifdef HAVE_AMESOS2_EPETRA
20# include <Epetra_RowMatrix.h>
21# include <Epetra_CrsMatrix.h>
22// # include <Epetra_MsrMatrix.h>
23# include <Epetra_VbrMatrix.h>
24// and perhaps some others later...
25#endif
26
27#include "Amesos2_Util.hpp"
28
29namespace Amesos2 {
30
31 // The declaration
32 template <class Matrix>
33 struct MatrixTraits {};
34
35 /*******************
36 * Specializations *
37 *******************/
38
39 template < typename Scalar,
40 typename LocalOrdinal,
41 typename GlobalOrdinal,
42 typename Node >
43 struct MatrixTraits<
44 Tpetra::RowMatrix<Scalar,
45 LocalOrdinal,
46 GlobalOrdinal,
47 Node> > {
48 typedef Scalar scalar_t;
49 typedef LocalOrdinal local_ordinal_t;
50 typedef GlobalOrdinal global_ordinal_t;
51 typedef Node node_t;
52
53 typedef Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> matrix_type;
54 typedef typename matrix_type::impl_scalar_type impl_scalar_type;
55
56 typedef typename matrix_type::nonconst_global_inds_host_view_type global_host_idx_type;
57 typedef typename matrix_type::nonconst_values_host_view_type global_host_val_type;
58
59 typedef row_access major_access;
60 };
61
62 template < typename Scalar,
63 typename LocalOrdinal,
64 typename GlobalOrdinal,
65 typename Node >
66 struct MatrixTraits<
67 Tpetra::CrsMatrix<Scalar,
68 LocalOrdinal,
69 GlobalOrdinal,
70 Node> > {
71 typedef Scalar scalar_t;
72 typedef LocalOrdinal local_ordinal_t;
73 typedef GlobalOrdinal global_ordinal_t;
74 typedef Node node_t;
75
76 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> matrix_type;
77 typedef typename matrix_type::impl_scalar_type impl_scalar_type;
78
79 typedef typename matrix_type::nonconst_global_inds_host_view_type global_host_idx_type;
80 typedef typename matrix_type::nonconst_values_host_view_type global_host_val_type;
81
82 typedef row_access major_access;
83 };
84
85 template < typename Scalar,
86 typename LocalOrdinal,
87 typename DeviceType >
88 struct MatrixTraits<
89 KokkosSparse::CrsMatrix<Scalar,
90 LocalOrdinal,
91 DeviceType> > {
92 typedef Scalar scalar_t;
93 typedef LocalOrdinal local_ordinal_t;
94 typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
95 typedef LocalOrdinal global_size_t;
96
97 typedef KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, DeviceType> matrix_type;
98 typedef Scalar impl_scalar_type;
99 typedef Tpetra::Map<>::node_type node_t;
100
101#if KOKKOS_VERSION >= 40799
102 typedef typename matrix_type::host_mirror_type::index_type global_host_idx_type;
103 typedef typename matrix_type::host_mirror_type::values_type global_host_val_type;
104#else
105 typedef typename matrix_type::HostMirror::index_type global_host_idx_type;
106 typedef typename matrix_type::HostMirror::values_type global_host_val_type;
107#endif
108
109 typedef row_access major_access;
110 };
111
112#ifdef HAVE_AMESOS2_EPETRA
113
114 template <>
115 struct MatrixTraits<Epetra_RowMatrix> {
116 typedef double scalar_t;
117 typedef double impl_scalar_type;
118 typedef int local_ordinal_t;
119 typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
120 typedef Tpetra::Map<>::node_type node_t;
121
122 typedef Epetra_RowMatrix matrix_type;
123 typedef matrix_type local_matrix_t;
124 typedef int* sparse_ptr_type;
125 typedef int* sparse_idx_type;
126 typedef double* sparse_values_type;
127
128 typedef Kokkos::View<global_ordinal_t*, Kokkos::HostSpace> global_host_idx_type;
129 typedef Kokkos::View<scalar_t*, Kokkos::HostSpace> global_host_val_type;
130
131 typedef row_access major_access;
132 };
133
134 template <>
135 struct MatrixTraits<Epetra_CrsMatrix> {
136 typedef double scalar_t;
137 typedef double impl_scalar_type;
138 typedef int local_ordinal_t;
139 typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
140 typedef Tpetra::Map<>::node_type node_t;
141
142 typedef Epetra_CrsMatrix matrix_type;
143 typedef matrix_type local_matrix_t;
144 typedef int* sparse_ptr_type;
145 typedef int* sparse_idx_type;
146 typedef double* sparse_values_type;
147
148 typedef Kokkos::View<global_ordinal_t*, Kokkos::HostSpace> global_host_idx_type;
149 typedef Kokkos::View<scalar_t*, Kokkos::HostSpace> global_host_val_type;
150
151 typedef row_access major_access;
152 };
153
154 // template <>
155 // struct MatrixTraits<Epetra_MsrMatrix> {
156 // typedef double scalar_t;
157 // typedef int local_ordinal_t;
158 // typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
159 // typedef Tpetra::Map<>::node_type node_t;
160
161 // typedef row_access major_access;
162 // };
163
164 template <>
165 struct MatrixTraits<Epetra_VbrMatrix> {
166 typedef double scalar_t;
167 typedef double impl_scalar_type;
168 typedef int local_ordinal_t;
169 typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
170 typedef Tpetra::Map<>::node_type node_t;
171
172 typedef Epetra_VbrMatrix matrix_type;
173 typedef matrix_type local_matrix_t;
174 typedef int* sparse_ptr_type;
175 typedef int* sparse_idx_type;
176 typedef double* sparse_values_type;
177
178 typedef row_access major_access;
179 };
180
181#endif
182
183}
184
185#endif // AMESOS2_MATRIXTRAITS_HPP
Utility functions for Amesos2.