Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superludist_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
22
23#ifndef AMESOS2_SUPERLUDIST_TYPEMAP_HPP
24#define AMESOS2_SUPERLUDIST_TYPEMAP_HPP
25
26//#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
27//#endif
28
29#include <functional>
30
31#include <Teuchos_as.hpp>
32#ifdef HAVE_TEUCHOS_COMPLEX
33#include <Teuchos_SerializationTraits.hpp>
34#endif
35
36#include "Amesos2_TypeMap.hpp"
37
38#ifdef KOKKOS_ENABLE_CUDA
39 #include <cublas_v2.h>
40 #include <cuda_runtime_api.h>
41#endif
42
43
44namespace SLUD {
45
46#if SUPERLU_DIST_MAJOR_VERSION > 4
47// SuperLU_Dist before major version 5 does not contain the config file
48#include "superlu_dist_config.h" // provides define for size 32 or 64 int_t
49#endif
50
52#define USER_FREE(addr) SLUD::superlu_free_dist(addr)
53
54 // undefine compiler guard in case we also have the sequential
55 // SuperLU enabled
56#undef __SUPERLU_SUPERMATRIX
57#include "superlu_defs.h"
58//
59
60#if SUPERLU_DIST_MAJOR_VERSION > 4
61 typedef superlu_dist_options_t amesos2_superlu_dist_options_t;
62 typedef superlu_dist_mem_usage_t amesos2_superlu_dist_mem_usage_t;
63#define AMESOS2_ENABLES_SUPERLUDIST_VERSION5_AND_HIGHER 1
64#else
65 typedef superlu_options_t amesos2_superlu_dist_options_t;
66 typedef mem_usage_t amesos2_superlu_dist_mem_usage_t;
67#endif
68
69#if SUPERLU_DIST_MAJOR_VERSION > 9 || (SUPERLU_DIST_MAJOR_VERSION == 9 && SUPERLU_DIST_MINOR_VERSION > 1)
70 typedef int perm_int_t;
71#else
72 typedef int_t perm_int_t;
73#endif
74
75#if SUPERLU_DIST_MAJOR_VERSION > 8
76 typedef int info_t;
77#else
78 typedef int_t info_t;
79#endif
80
81 namespace D {
82#include "superlu_ddefs.h" // double-precision real definitions
83 }
84
85#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
86 namespace Z {
87#include "superlu_zdefs.h" // double-precision complex definitions
88 }
89#endif // HAVE_TEUCHOS_COMPLEX
90
91#undef EMPTY
92
93// multiplication of SLUD types
94template <typename slu_scalar_t, typename slu_mag_t>
95struct slu_dist_mult {};
96
97// This specialization handles the generic case were the scalar and
98// magnitude types are double or float.
99template <typename T>
100struct slu_dist_mult<T,T> : std::multiplies<T> {};
101
102// For namespace/macro reasons, we prefix our variables with amesos_*
103template <>
104struct slu_dist_mult<double,double>
105{
106 double operator()(double a, double b) {
107 return( a*b );
108 }
109};
110
111#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
112
113 template <>
114 struct slu_dist_mult<Z::doublecomplex,double>
115 {
116 Z::doublecomplex operator()(Z::doublecomplex amesos_z, double amesos_d) {
117 Z::doublecomplex amesos_zr;
118 zd_mult(&amesos_zr, &amesos_z, amesos_d); // zd_mult is a macro, so no namespacing
119 return( amesos_zr );
120 }
121 };
122
123 template <>
124 struct slu_dist_mult<Z::doublecomplex,Z::doublecomplex>
125 {
126 Z::doublecomplex operator()(Z::doublecomplex amesos_z1, Z::doublecomplex amesos_z2) {
127 Z::doublecomplex amesos_zr;
128 zz_mult(&amesos_zr, &amesos_z1, &amesos_z2); // zz_mult is a macro, so no namespacing
129 return( amesos_zr );
130 }
131 };
132#endif // HAVE_TEUCHOS_COMPLEX
133} // end namespace SLUD
134#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
135
136
137/* ==================== Conversion ==================== */
138namespace Teuchos {
139
150template <typename TypeFrom>
151class ValueTypeConversionTraits<SLUD::Z::doublecomplex, TypeFrom>
152{
153public:
154 static SLUD::Z::doublecomplex convert( const TypeFrom t )
155 {
156 SLUD::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 SLUD::Z::doublecomplex safeConvert( const TypeFrom t )
163 {
164 SLUD::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, SLUD::Z::doublecomplex>
175{
176public:
177 static TypeTo convert( const SLUD::Z::doublecomplex 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 SLUD::Z::doublecomplex 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
195template <typename Ordinal>
196class SerializationTraits<Ordinal,SLUD::Z::doublecomplex>
197 : public DirectSerializationTraits<Ordinal,SLUD::Z::doublecomplex>
198{};
199
201
202} // end namespace Teuchos
203
204
205
211namespace std {
212 // C++-style output functions for Superludist complex types
213 ostream& operator<<(ostream& out, const SLUD::Z::doublecomplex z);
214
216}
217#endif // HAVE_TEUCHOS_COMPLEX
218
219
220
221namespace Amesos2 {
222
223template <class, class> class Superludist;
224
225/* Specialize the Amesos2::TypeMap struct for SuperLU_DIST types
226 *
227 * \cond Superludist_type_specializations
228 */
229template <>
230struct TypeMap<Superludist,double>
231{
232 static const SLUD::Dtype_t dtype = SLUD::SLU_D;
233 typedef double type;
234 typedef double magnitude_type;
235#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
236 typedef SLUD::D::dLUstruct_t LUstruct_t;
237 typedef SLUD::D::dSOLVEstruct_t SOLVEstruct_t;
238 typedef SLUD::D::dScalePermstruct_t ScalePermstruct_t;
239#else
240 typedef SLUD::D::LUstruct_t LUstruct_t;
241 typedef SLUD::D::SOLVEstruct_t SOLVEstruct_t;
242 typedef SLUD::ScalePermstruct_t ScalePermstruct_t;
243#endif
244};
245
246#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
247template <>
248struct TypeMap<Superludist,std::complex<double> >
249{
250 static const SLUD::Dtype_t dtype = SLUD::SLU_Z;
251 typedef SLUD::Z::doublecomplex type;
252 typedef double magnitude_type;
253#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
254 typedef SLUD::Z::zLUstruct_t LUstruct_t;
255 typedef SLUD::Z::zSOLVEstruct_t SOLVEstruct_t;
256 typedef SLUD::Z::zScalePermstruct_t ScalePermstruct_t;
257#else
258 typedef SLUD::Z::LUstruct_t LUstruct_t;
259 typedef SLUD::Z::SOLVEstruct_t SOLVEstruct_t;
260 typedef SLUD::ScalePermstruct_t ScalePermstruct_t;
261#endif
262};
263
264 // It probably won't happen, but what if someone does create a
265 // matrix or multivector with the SuperLU_DIST doublecomplex type
266 // directly?
267template <>
268struct TypeMap<Superludist,SLUD::Z::doublecomplex>
269{
270 static const SLUD::Dtype_t dtype = SLUD::SLU_Z;
271 typedef SLUD::Z::doublecomplex type;
272 typedef double magnitude_type;
273#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
274 typedef SLUD::Z::zLUstruct_t LUstruct_t;
275 typedef SLUD::Z::zSOLVEstruct_t SOLVEstruct_t;
276 typedef SLUD::Z::zScalePermstruct_t ScalePermstruct_t;
277#else
278 typedef SLUD::Z::LUstruct_t LUstruct_t;
279 typedef SLUD::Z::SOLVEstruct_t SOLVEstruct_t;
280 typedef SLUD::ScalePermstruct_t ScalePermstruct_t;
281#endif
282};
283
284#endif // HAVE_TEUCHOS_COMPLEX
285
286/* \endcond Superludist_type_specializations */
287
288
289} // end namespace Amesos2
290
291#endif // AMESOS2_SUPERLUDIST_TYPEMAP_HPP
Amesos2 interface to the distributed memory version of SuperLU.
Definition Amesos2_Superludist_decl.hpp:57
Map types to solver-specific data-types and enums.
Definition Amesos2_TypeMap.hpp:48