Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superludist_TypeMap.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Amesos2: Templated Direct Sparse Solver Package
6// Copyright 2011 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39//
40// ***********************************************************************
41//
42// @HEADER
43
56
57#ifndef AMESOS2_SUPERLUDIST_TYPEMAP_HPP
58#define AMESOS2_SUPERLUDIST_TYPEMAP_HPP
59
60//#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
61//#endif
62
63#include <functional>
64
65#include <Teuchos_as.hpp>
66#ifdef HAVE_TEUCHOS_COMPLEX
67#include <Teuchos_SerializationTraits.hpp>
68#endif
69
70#include "Amesos2_TypeMap.hpp"
71
72
73namespace SLUD {
74
75extern "C" {
76
77#if SUPERLU_DIST_MAJOR_VERSION > 4
78// SuperLU_Dist before major version 5 does not contain the config file
79#include "superlu_dist_config.h" // provides define for size 32 or 64 int_t
80#endif
81
83#define USER_FREE(addr) SLUD::superlu_free_dist(addr)
84
85 // undefine compiler guard in case we also have the sequential
86 // SuperLU enabled
87#undef __SUPERLU_SUPERMATRIX
88#include "superlu_defs.h"
89//
90
91#if SUPERLU_DIST_MAJOR_VERSION > 4
92 typedef superlu_dist_options_t amesos2_superlu_dist_options_t;
93 typedef superlu_dist_mem_usage_t amesos2_superlu_dist_mem_usage_t;
94#define AMESOS2_ENABLES_SUPERLUDIST_VERSION5_AND_HIGHER 1
95#else
96 typedef superlu_options_t amesos2_superlu_dist_options_t;
97 typedef mem_usage_t amesos2_superlu_dist_mem_usage_t;
98#endif
99
100
101 namespace D {
102#include "superlu_ddefs.h" // double-precision real definitions
103 }
104
105#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
106 namespace Z {
107#include "superlu_zdefs.h" // double-precision complex definitions
108 }
109#endif // HAVE_TEUCHOS_COMPLEX
110
111
112} // end extern "C"
113
114// Declare and specialize a std::binary_funtion class for
115// multiplication of SLUD types
116template <typename slu_scalar_t, typename slu_mag_t>
117struct slu_dist_mult {};
118
119// This specialization handles the generic case were the scalar and
120// magnitude types are double or float.
121template <typename T>
122struct slu_dist_mult<T,T> : std::multiplies<T> {};
123
124// For namespace/macro reasons, we prefix our variables with amesos_*
125template <>
126struct slu_dist_mult<double,double>
127 : std::binary_function<double,double,double> {
128 double operator()(double a, double b) {
129 return( a*b );
130 }
131};
132
133#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
134
135 template <>
136 struct slu_dist_mult<Z::doublecomplex,double>
137 : std::binary_function<Z::doublecomplex,double,Z::doublecomplex> {
138 Z::doublecomplex operator()(Z::doublecomplex amesos_z, double amesos_d) {
139 Z::doublecomplex amesos_zr;
140 zd_mult(&amesos_zr, &amesos_z, amesos_d); // zd_mult is a macro, so no namespacing
141 return( amesos_zr );
142 }
143 };
144
145 template <>
146 struct slu_dist_mult<Z::doublecomplex,Z::doublecomplex>
147 : std::binary_function<Z::doublecomplex,Z::doublecomplex,Z::doublecomplex> {
148 Z::doublecomplex operator()(Z::doublecomplex amesos_z1, Z::doublecomplex amesos_z2) {
149 Z::doublecomplex amesos_zr;
150 zz_mult(&amesos_zr, &amesos_z1, &amesos_z2); // zz_mult is a macro, so no namespacing
151 return( amesos_zr );
152 }
153 };
154#endif // HAVE_TEUCHOS_COMPLEX
155} // end namespace SLUD
156#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
157
158
159/* ==================== Conversion ==================== */
160namespace Teuchos {
161
172template <typename TypeFrom>
173class ValueTypeConversionTraits<SLUD::Z::doublecomplex, TypeFrom>
174{
175public:
176 static SLUD::Z::doublecomplex convert( const TypeFrom t )
177 {
178 SLUD::Z::doublecomplex ret;
179 ret.r = Teuchos::as<double>(t.real());
180 ret.i = Teuchos::as<double>(t.imag());
181 return( ret );
182 }
183
184 static SLUD::Z::doublecomplex safeConvert( const TypeFrom t )
185 {
186 SLUD::Z::doublecomplex ret;
187 ret.r = Teuchos::as<double>(t.real());
188 ret.i = Teuchos::as<double>(t.imag());
189 return( ret );
190 }
191};
192
193
194// Also convert from SLU types
195template <typename TypeTo>
196class ValueTypeConversionTraits<TypeTo, SLUD::Z::doublecomplex>
197{
198public:
199 static TypeTo convert( const SLUD::Z::doublecomplex t )
200 {
201 typedef typename TypeTo::value_type value_type;
202 value_type ret_r = Teuchos::as<value_type>( t.r );
203 value_type ret_i = Teuchos::as<value_type>( t.i );
204 return ( TypeTo( ret_r, ret_i ) );
205 }
206
207 // No special checks for safe Convert
208 static TypeTo safeConvert( const SLUD::Z::doublecomplex t )
209 {
210 typedef typename TypeTo::value_type value_type;
211 value_type ret_r = Teuchos::as<value_type>( t.r );
212 value_type ret_i = Teuchos::as<value_type>( t.i );
213 return ( TypeTo( ret_r, ret_i ) );
214 }
215};
216
217template <typename Ordinal>
218class SerializationTraits<Ordinal,SLUD::Z::doublecomplex>
219 : public DirectSerializationTraits<Ordinal,SLUD::Z::doublecomplex>
220{};
221
223
224} // end namespace Teuchos
225
226
227
233namespace std {
234 // C++-style output functions for Superludist complex types
235 ostream& operator<<(ostream& out, const SLUD::Z::doublecomplex z);
236
238}
239#endif // HAVE_TEUCHOS_COMPLEX
240
241
242
243namespace Amesos2 {
244
245template <class, class> class Superludist;
246
247/* Specialize the Amesos2::TypeMap struct for SuperLU_DIST types
248 *
249 * \cond Superludist_type_specializations
250 */
251template <>
252struct TypeMap<Superludist,double>
253{
254 static const SLUD::Dtype_t dtype = SLUD::SLU_D;
255 typedef double type;
256 typedef double magnitude_type;
257#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
258 typedef SLUD::D::dLUstruct_t LUstruct_t;
259 typedef SLUD::D::dSOLVEstruct_t SOLVEstruct_t;
260 typedef SLUD::D::dScalePermstruct_t ScalePermstruct_t;
261#else
262 typedef SLUD::D::LUstruct_t LUstruct_t;
263 typedef SLUD::D::SOLVEstruct_t SOLVEstruct_t;
264 typedef SLUD::ScalePermstruct_t ScalePermstruct_t;
265#endif
266};
267
268#if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
269template <>
270struct TypeMap<Superludist,std::complex<double> >
271{
272 static const SLUD::Dtype_t dtype = SLUD::SLU_Z;
273 typedef SLUD::Z::doublecomplex type;
274 typedef double magnitude_type;
275#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
276 typedef SLUD::Z::zLUstruct_t LUstruct_t;
277 typedef SLUD::Z::zSOLVEstruct_t SOLVEstruct_t;
278 typedef SLUD::Z::zScalePermstruct_t ScalePermstruct_t;
279#else
280 typedef SLUD::Z::LUstruct_t LUstruct_t;
281 typedef SLUD::Z::SOLVEstruct_t SOLVEstruct_t;
282 typedef SLUD::ScalePermstruct_t ScalePermstruct_t;
283#endif
284};
285
286 // It probably won't happen, but what if someone does create a
287 // matrix or multivector with the SuperLU_DIST doublecomplex type
288 // directly?
289template <>
290struct TypeMap<Superludist,SLUD::Z::doublecomplex>
291{
292 static const SLUD::Dtype_t dtype = SLUD::SLU_Z;
293 typedef SLUD::Z::doublecomplex type;
294 typedef double magnitude_type;
295#if SUPERLU_DIST_MAJOR_VERSION > 6 || (SUPERLU_DIST_MAJOR_VERSION == 6 && SUPERLU_DIST_MINOR_VERSION > 2)
296 typedef SLUD::Z::zLUstruct_t LUstruct_t;
297 typedef SLUD::Z::zSOLVEstruct_t SOLVEstruct_t;
298 typedef SLUD::Z::zScalePermstruct_t ScalePermstruct_t;
299#else
300 typedef SLUD::Z::LUstruct_t LUstruct_t;
301 typedef SLUD::Z::SOLVEstruct_t SOLVEstruct_t;
302 typedef SLUD::ScalePermstruct_t ScalePermstruct_t;
303#endif
304};
305
306#endif // HAVE_TEUCHOS_COMPLEX
307
308/* \endcond Superludist_type_specializations */
309
310
311} // end namespace Amesos2
312
313#endif // AMESOS2_SUPERLUDIST_TYPEMAP_HPP
Amesos2 interface to the distributed memory version of SuperLU.
Definition Amesos2_Superludist_decl.hpp:91
Map types to solver-specific data-types and enums.
Definition Amesos2_TypeMap.hpp:82