Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superlu_TypeMap.hpp
Go to the documentation of this file.
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
20#ifndef AMESOS2_SUPERLU_TYPEMAP_HPP
21#define AMESOS2_SUPERLU_TYPEMAP_HPP
22
23#include <functional>
24#ifdef HAVE_TEUCHOS_COMPLEX
25#include <complex>
26#endif
27
28#include <Teuchos_as.hpp>
29#ifdef HAVE_TEUCHOS_COMPLEX
30#include <Teuchos_SerializationTraits.hpp>
31#endif
32
33#include "Amesos2_TypeMap.hpp"
34
35/* The SuperLU comples headers file only need to be included if
36 complex has been enabled in Teuchos. In addition we only need to
37 define the conversion and printing functions if complex has been
38 enabled. */
39namespace SLU {
40
41typedef int int_t;
42
43extern "C" {
44
45#undef __SUPERLU_SUPERMATRIX
46#include "supermatrix.h" // for Dtype_t declaration
47
48#ifdef HAVE_TEUCHOS_COMPLEX
49namespace C {
50#undef __SUPERLU_SCOMPLEX
51#undef SCOMPLEX_INCLUDE
52#include "slu_scomplex.h" // single-precision complex data type definitions
53}
54
55namespace Z {
56#undef __SUPERLU_DCOMPLEX
57#undef DCOMPLEX_INCLUDE
58#include "slu_dcomplex.h" // double-precision complex data type definitions
59}
60#endif // HAVE_TEUCHOS_COMPLEX
61
62} // end extern "C"
63
64} // end namespace SLU
65
66#ifdef HAVE_TEUCHOS_COMPLEX
67
68/* ==================== Conversion ==================== */
69namespace Teuchos {
70
78template <>
79class ValueTypeConversionTraits<SLU::C::complex, Kokkos::complex<float>>
80{
81public:
82 static SLU::C::complex convert( const Kokkos::complex<float> t ) {
83 SLU::C::complex ret;
84 ret.r = t.real();
85 ret.i = t.imag();
86 return( ret );
87 }
88
89 static SLU::C::complex safeConvert( const Kokkos::complex<float> t ) {
90 SLU::C::complex ret;
91 ret.r = t.real();
92 ret.i = t.imag();
93 return( ret );
94 }
95};
96
97template <>
98class ValueTypeConversionTraits<SLU::Z::doublecomplex, Kokkos::complex<double>>
99{
100public:
101 static SLU::Z::doublecomplex convert( const Kokkos::complex<double> t ) {
102 SLU::Z::doublecomplex ret;
103 ret.r = t.real();
104 ret.i = t.imag();
105 return( ret );
106 }
107
108 static SLU::Z::doublecomplex safeConvert( const Kokkos::complex<double> t ) {
109 SLU::Z::doublecomplex ret;
110 ret.r = t.real();
111 ret.i = t.imag();
112 return( ret );
113 }
114};
115
116// Also convert from SLU types
117
118template <>
119class ValueTypeConversionTraits<Kokkos::complex<float>, SLU::C::complex>
120{
121public:
122 static Kokkos::complex<float> convert( const SLU::C::complex t ) {
123 return ( Kokkos::complex<float>( t.r, t.i ) );
124 }
125
126 static Kokkos::complex<float> safeConvert( const SLU::C::complex t ) {
127 return ( Kokkos::complex<float>( t.r, t.i ) );
128 }
129};
130
131template <>
132class ValueTypeConversionTraits<Kokkos::complex<double>, SLU::Z::doublecomplex>
133{
134public:
135 static Kokkos::complex<double> convert( const SLU::Z::doublecomplex t ) {
136 return ( Kokkos::complex<double>( t.r, t.i ) );
137 }
138
139 static Kokkos::complex<double> safeConvert( const SLU::Z::doublecomplex t ) {
140 return ( Kokkos::complex<double>( t.r, t.i ) );
141 }
142};
143
145
146} // end namespace Teuchos
147
148#endif // HAVE_TEUCHOS_COMPLEX
149
150namespace Amesos2 {
151
152template <class, class> class Superlu;
153
154/* Specialize the Amesos2::TypeMap struct for Superlu types
155 *
156 * \cond Superlu_type_specializations
157 */
158template <>
159struct TypeMap<Superlu,float>
160{
161 static SLU::Dtype_t dtype;
162 typedef float convert_type;
163 typedef float type;
164 typedef float magnitude_type;
165};
166
167
168template <>
169struct TypeMap<Superlu,double>
170{
171 static SLU::Dtype_t dtype;
172 typedef double convert_type;
173 typedef double type;
174 typedef double magnitude_type;
175};
176
177
178#ifdef HAVE_TEUCHOS_COMPLEX
179
180template <>
181struct TypeMap<Superlu,std::complex<float> >
182{
183 static SLU::Dtype_t dtype;
184 typedef SLU::C::complex convert_type; // to create array before calling superlu
185 typedef Kokkos::complex<float> type;
186 typedef float magnitude_type;
187};
188
189
190template <>
191struct TypeMap<Superlu,std::complex<double> >
192{
193 static SLU::Dtype_t dtype;
194 typedef SLU::Z::doublecomplex convert_type; // to create array before calling superlu
195 typedef Kokkos::complex<double> type;
196 typedef double magnitude_type;
197};
198
199
200template <>
201struct TypeMap<Superlu,Kokkos::complex<float> >
202{
203 static SLU::Dtype_t dtype;
204 typedef SLU::C::complex convert_type; // to create array before calling superlu
205 typedef Kokkos::complex<float> type;
206 typedef float magnitude_type;
207};
208
209
210template <>
211struct TypeMap<Superlu,Kokkos::complex<double> >
212{
213 static SLU::Dtype_t dtype;
214 typedef SLU::Z::doublecomplex convert_type; // to create array before calling superlu
215 typedef Kokkos::complex<double> type;
216 typedef double magnitude_type;
217};
218
219
220#endif // HAVE_TEUCHOS_COMPLEX
221
222/* \endcond Superlu_type_specializations */
223
224
225} // end namespace Amesos2
226
227#endif // AMESOS2_SUPERLU_TYPEMAP_HPP