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 
29 namespace 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  typedef typename matrix_type::HostMirror::index_type global_host_idx_type;
102  typedef typename matrix_type::HostMirror::values_type global_host_val_type;
103 
104  typedef row_access major_access;
105  };
106 
107 #ifdef HAVE_AMESOS2_EPETRA
108 
109  template <>
110  struct MatrixTraits<Epetra_RowMatrix> {
111  typedef double scalar_t;
112  typedef double impl_scalar_type;
113  typedef int local_ordinal_t;
114  typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
115  typedef Tpetra::Map<>::node_type node_t;
116 
117  typedef Epetra_RowMatrix matrix_type;
118  typedef matrix_type local_matrix_t;
119  typedef int* sparse_ptr_type;
120  typedef int* sparse_idx_type;
121  typedef double* sparse_values_type;
122 
123  typedef Kokkos::View<global_ordinal_t*, Kokkos::HostSpace> global_host_idx_type;
124  typedef Kokkos::View<scalar_t*, Kokkos::HostSpace> global_host_val_type;
125 
126  typedef row_access major_access;
127  };
128 
129  template <>
130  struct MatrixTraits<Epetra_CrsMatrix> {
131  typedef double scalar_t;
132  typedef double impl_scalar_type;
133  typedef int local_ordinal_t;
134  typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
135  typedef Tpetra::Map<>::node_type node_t;
136 
137  typedef Epetra_CrsMatrix matrix_type;
138  typedef matrix_type local_matrix_t;
139  typedef int* sparse_ptr_type;
140  typedef int* sparse_idx_type;
141  typedef double* sparse_values_type;
142 
143  typedef Kokkos::View<global_ordinal_t*, Kokkos::HostSpace> global_host_idx_type;
144  typedef Kokkos::View<scalar_t*, Kokkos::HostSpace> global_host_val_type;
145 
146  typedef row_access major_access;
147  };
148 
149  // template <>
150  // struct MatrixTraits<Epetra_MsrMatrix> {
151  // typedef double scalar_t;
152  // typedef int local_ordinal_t;
153  // typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
154  // typedef Tpetra::Map<>::node_type node_t;
155 
156  // typedef row_access major_access;
157  // };
158 
159  template <>
160  struct MatrixTraits<Epetra_VbrMatrix> {
161  typedef double scalar_t;
162  typedef double impl_scalar_type;
163  typedef int local_ordinal_t;
164  typedef Tpetra::Map<>::global_ordinal_type global_ordinal_t;
165  typedef Tpetra::Map<>::node_type node_t;
166 
167  typedef Epetra_VbrMatrix matrix_type;
168  typedef matrix_type local_matrix_t;
169  typedef int* sparse_ptr_type;
170  typedef int* sparse_idx_type;
171  typedef double* sparse_values_type;
172 
173  typedef row_access major_access;
174  };
175 
176 #endif
177 
178 }
179 
180 #endif // AMESOS2_MATRIXTRAITS_HPP
Utility functions for Amesos2.