Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superlumt_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_SUPERLUMT_TYPEMAP_HPP
21#define AMESOS2_SUPERLUMT_TYPEMAP_HPP
22
23#include <functional>
24
25#include <Teuchos_as.hpp>
26#ifdef HAVE_TEUCHOS_COMPLEX
27#include <Teuchos_SerializationTraits.hpp>
28#endif
29
30#include "Amesos2_TypeMap.hpp"
31
32namespace SLUMT {
33
34typedef int int_t;
35
36extern "C" {
37
38#undef __SUPERLU_SUPERMATRIX
39#include "supermatrix.h" // for Dtype_t declaration
40
41#ifdef HAVE_TEUCHOS_COMPLEX
42
43namespace C {
44#undef __SUPERLU_SCOMPLEX
45#undef SCOMPLEX_INCLUDE
46#include "slu_scomplex.h" // single-precision complex data type definitions
47}
48
49namespace Z {
50#undef __SUPERLU_DCOMPLEX
51#undef DCOMPLEX_INCLUDE
52#include "slu_dcomplex.h" // double-precision complex data type definitions
53}
54
55#endif // HAVE_TEUCHOS_COMPLEX
56
57} // end extern "C"
58
59 // multiplication of SLUMT types
60 template <typename slu_scalar_t, typename slu_mag_t>
61 struct slu_mt_mult {};
62
63 // This specialization handles the generic case were the scalar and
64 // magnitude types are double or float.
65 template <typename T>
66 struct slu_mt_mult<T,T> : std::multiplies<T> {};
67
68#ifdef HAVE_TEUCHOS_COMPLEX
69
70 // For namespace/macro reasons, we prefix our variables with amesos_*
71 template <>
72 struct slu_mt_mult<C::complex,float>
73 {
74 C::complex operator()(C::complex amesos_c, float amesos_f) {
75 C::complex amesos_cr;
76 cs_mult(&amesos_cr, &amesos_c, amesos_f); // cs_mult is a macro, so no namespacing
77 return( amesos_cr );
78 }
79 };
80
81 template <>
82 struct slu_mt_mult<C::complex,C::complex>
83 {
84 C::complex operator()(C::complex amesos_c1, C::complex amesos_c2) {
85 C::complex amesos_cr;
86 cc_mult(&amesos_cr, &amesos_c1, &amesos_c2); // cc_mult is a macro, so no namespacing
87 return( amesos_cr );
88 }
89 };
90
91 template <>
92 struct slu_mt_mult<Z::doublecomplex,double>
93 {
94 Z::doublecomplex operator()(Z::doublecomplex amesos_z, double amesos_d) {
95 Z::doublecomplex amesos_zr;
96 zd_mult(&amesos_zr, &amesos_z, amesos_d); // zd_mult is a macro, so no namespacing
97 return( amesos_zr );
98 }
99 };
100
101 template <>
102 struct slu_mt_mult<Z::doublecomplex,Z::doublecomplex>
103 {
104 Z::doublecomplex operator()(Z::doublecomplex amesos_z1, Z::doublecomplex amesos_z2) {
105 Z::doublecomplex amesos_zr;
106 zz_mult(&amesos_zr, &amesos_z1, &amesos_z2); // zz_mult is a macro, so no namespacing
107 return( amesos_zr );
108 }
109 };
110
111#endif // HAVE_TEUCHOS_COMPLEX
112} // end namespace SLUMt
113#ifdef HAVE_TEUCHOS_COMPLEX
114
115/* ==================== Conversion ==================== */
116namespace Teuchos {
117
128template <typename TypeFrom>
129class ValueTypeConversionTraits<SLUMT::C::complex, TypeFrom>
130{
131public:
132 static SLUMT::C::complex convert( const TypeFrom t )
133 {
134 SLUMT::C::complex ret;
135 ret.r = Teuchos::as<float>(t.real());
136 ret.i = Teuchos::as<float>(t.imag());
137 return( ret );
138 }
139
140 static SLUMT::C::complex safeConvert( const TypeFrom t )
141 {
142 SLUMT::C::complex ret;
143 ret.r = Teuchos::as<float>(t.real());
144 ret.i = Teuchos::as<float>(t.imag());
145 return( ret );
146 }
147};
148
149
150template <typename TypeFrom>
151class ValueTypeConversionTraits<SLUMT::Z::doublecomplex, TypeFrom>
152{
153public:
154 static SLUMT::Z::doublecomplex convert( const TypeFrom t )
155 {
156 SLUMT::Z::doublecomplex ret;
157 ret.r = Teuchos::as<double>(t.real());
158 ret.i = Teuchos::as<double>(t.imag());
159 return( ret );
160 }
161
162 static SLUMT::Z::doublecomplex safeConvert( const TypeFrom t )
163 {
164 SLUMT::Z::doublecomplex ret;
165 ret.r = Teuchos::as<double>(t.real());
166 ret.i = Teuchos::as<double>(t.imag());
167 return( ret );
168 }
169};
170
171
172// Also convert from SLU types
173template <typename TypeTo>
174class ValueTypeConversionTraits<TypeTo, SLUMT::C::complex>
175{
176public:
177 static TypeTo convert( const SLUMT::C::complex t )
178 {
179 typedef typename TypeTo::value_type value_type;
180 value_type ret_r = Teuchos::as<value_type>( t.r );
181 value_type ret_i = Teuchos::as<value_type>( t.i );
182 return ( TypeTo( ret_r, ret_i ) );
183 }
184
185 // No special checks for safe Convert
186 static TypeTo safeConvert( const SLUMT::C::complex t )
187 {
188 typedef typename TypeTo::value_type value_type;
189 value_type ret_r = Teuchos::as<value_type>( t.r );
190 value_type ret_i = Teuchos::as<value_type>( t.i );
191 return ( TypeTo( ret_r, ret_i ) );
192 }
193};
194
195
196template <typename TypeTo>
197class ValueTypeConversionTraits<TypeTo, SLUMT::Z::doublecomplex>
198{
199public:
200 static TypeTo convert( const SLUMT::Z::doublecomplex t )
201 {
202 typedef typename TypeTo::value_type value_type;
203 value_type ret_r = Teuchos::as<value_type>( t.r );
204 value_type ret_i = Teuchos::as<value_type>( t.i );
205 return ( TypeTo( ret_r, ret_i ) );
206 }
207
208 // No special checks for safe Convert
209 static TypeTo safeConvert( const SLUMT::Z::doublecomplex t )
210 {
211 typedef typename TypeTo::value_type value_type;
212 value_type ret_r = Teuchos::as<value_type>( t.r );
213 value_type ret_i = Teuchos::as<value_type>( t.i );
214 return ( TypeTo( ret_r, ret_i ) );
215 }
216};
217
218template <typename Ordinal>
219class SerializationTraits<Ordinal,SLUMT::C::complex>
220 : public DirectSerializationTraits<Ordinal,SLUMT::C::complex>
221{};
222
223template <typename Ordinal>
224class SerializationTraits<Ordinal,SLUMT::Z::doublecomplex>
225 : public DirectSerializationTraits<Ordinal,SLUMT::Z::doublecomplex>
226{};
227
229
230} // end namespace Teuchos
231
232
233
239namespace std {
240 // C++-style output functions for Superlumt complex types
241 ostream& operator<<(ostream& out, const SLUMT::C::complex c);
242
243 ostream& operator<<(ostream& out, const SLUMT::Z::doublecomplex z);
244
246}
247
248#endif // HAVE_TEUCHOS_COMPLEX
249
250
251namespace Amesos2 {
252
253template <class, class> class Superlumt;
254
255/* Specialize the Amesos2::TypeMap struct for Superlumt types
256 *
257 * \cond Superlumt_type_specializations
258 */
259template <>
260struct TypeMap<Superlumt,float>
261{
262 static SLUMT::Dtype_t dtype;
263 typedef float type;
264 typedef float magnitude_type;
265};
266
267
268template <>
269struct TypeMap<Superlumt,double>
270{
271 static SLUMT::Dtype_t dtype;
272 typedef double type;
273 typedef double magnitude_type;
274};
275
276
277#ifdef HAVE_TEUCHOS_COMPLEX
278template <>
279struct TypeMap<Superlumt,std::complex<float> >
280{
281 static SLUMT::Dtype_t dtype;
282 typedef SLUMT::C::complex type;
283 typedef float magnitude_type;
284};
285
286
287template <>
288struct TypeMap<Superlumt,std::complex<double> >
289{
290 static SLUMT::Dtype_t dtype;
291 typedef SLUMT::Z::doublecomplex type;
292 typedef double magnitude_type;
293};
294
295
296template <>
297struct TypeMap<Superlumt,SLUMT::C::complex>
298{
299 static SLUMT::Dtype_t dtype;
300 typedef SLUMT::C::complex type;
301 typedef float magnitude_type;
302};
303
304
305template <>
306struct TypeMap<Superlumt,SLUMT::Z::doublecomplex>
307{
308 static SLUMT::Dtype_t dtype;
309 typedef SLUMT::Z::doublecomplex type;
310 typedef double magnitude_type;
311};
312
313#endif // HAVE_TEUCHOS_COMPLEX
314
315/* \endcond Superlumt_type_specializations */
316
317
318} // end namespace Amesos2
319
320#endif // AMESOS2_SUPERLUMT_TYPEMAP_HPP