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 
57 #ifndef AMESOS2_SUPERLUDIST_TYPEMAP_HPP
58 #define AMESOS2_SUPERLUDIST_TYPEMAP_HPP
59 
60 #include <functional>
61 
62 #include <Teuchos_as.hpp>
63 #ifdef HAVE_TEUCHOS_COMPLEX
64 #include <Teuchos_SerializationTraits.hpp>
65 #endif
66 
67 #include "Amesos2_TypeMap.hpp"
68 
69 namespace SLUD {
70 
71 extern "C" {
72 
73  // undefine compiler guard in case we also have the sequential
74  // SuperLU enabled
75 #undef __SUPERLU_SUPERMATRIX
76 #include "superlu_defs.h"
77 
78  namespace D {
79 #include "superlu_ddefs.h" // double-precision real definitions
80  }
81 
82 #ifdef HAVE_TEUCHOS_COMPLEX
83  namespace Z {
84 #include "superlu_zdefs.h" // double-precision complex definitions
85  }
86 #endif // HAVE_TEUCHOS_COMPLEX
87 
88 } // end extern "C"
89 #ifdef HAVE_TEUCHOS_COMPLEX
90 
91  // Declare and specialize a std::binary_funtion class for
92  // multiplication of SLUD types
93  template <typename slu_scalar_t, typename slu_mag_t>
94  struct slu_mt_mult {};
95 
96  // This specialization handles the generic case were the scalar and
97  // magnitude types are double or float.
98  template <typename T>
99  struct slu_mt_mult<T,T> : std::multiplies<T> {};
100 
101  // For namespace/macro reasons, we prefix our variables with amesos_*
102  template <>
103  struct slu_mt_mult<Z::doublecomplex,double>
104  : std::binary_function<Z::doublecomplex,double,Z::doublecomplex> {
105  Z::doublecomplex operator()(Z::doublecomplex amesos_z, double amesos_d) {
106  Z::doublecomplex amesos_zr;
107  zd_mult(&amesos_zr, &amesos_z, amesos_d); // zd_mult is a macro, so no namespacing
108  return( amesos_zr );
109  }
110  };
111 
112  template <>
113  struct slu_mt_mult<Z::doublecomplex,Z::doublecomplex>
114  : std::binary_function<Z::doublecomplex,Z::doublecomplex,Z::doublecomplex> {
115  Z::doublecomplex operator()(Z::doublecomplex amesos_z1, Z::doublecomplex amesos_z2) {
116  Z::doublecomplex amesos_zr;
117  zz_mult(&amesos_zr, &amesos_z1, &amesos_z2); // zz_mult is a macro, so no namespacing
118  return( amesos_zr );
119  }
120  };
121 #endif // HAVE_TEUCHOS_COMPLEX
122 } // end namespace SLUD
123 #ifdef HAVE_TEUCHOS_COMPLEX
124 
125 
126 /* ==================== Conversion ==================== */
127 namespace Teuchos {
128 
139 template <typename TypeFrom>
140 class ValueTypeConversionTraits<SLUD::Z::doublecomplex, TypeFrom>
141 {
142 public:
143  static SLUD::Z::doublecomplex convert( const TypeFrom t )
144  {
145  SLUD::Z::doublecomplex ret;
146  ret.r = Teuchos::as<double>(t.real());
147  ret.i = Teuchos::as<double>(t.imag());
148  return( ret );
149  }
150 
151  static SLUD::Z::doublecomplex safeConvert( const TypeFrom t )
152  {
153  SLUD::Z::doublecomplex ret;
154  ret.r = Teuchos::as<double>(t.real());
155  ret.i = Teuchos::as<double>(t.imag());
156  return( ret );
157  }
158 };
159 
160 
161 // Also convert from SLU types
162 template <typename TypeTo>
163 class ValueTypeConversionTraits<TypeTo, SLUD::Z::doublecomplex>
164 {
165 public:
166  static TypeTo convert( const SLUD::Z::doublecomplex t )
167  {
168  typedef typename TypeTo::value_type value_type;
169  value_type ret_r = Teuchos::as<value_type>( t.r );
170  value_type ret_i = Teuchos::as<value_type>( t.i );
171  return ( TypeTo( ret_r, ret_i ) );
172  }
173 
174  // No special checks for safe Convert
175  static TypeTo safeConvert( const SLUD::Z::doublecomplex t )
176  {
177  typedef typename TypeTo::value_type value_type;
178  value_type ret_r = Teuchos::as<value_type>( t.r );
179  value_type ret_i = Teuchos::as<value_type>( t.i );
180  return ( TypeTo( ret_r, ret_i ) );
181  }
182 };
183 
184 template <typename Ordinal>
185 class SerializationTraits<Ordinal,SLUD::Z::doublecomplex>
186  : public DirectSerializationTraits<Ordinal,SLUD::Z::doublecomplex>
187 {};
188 
190 
191 } // end namespace Teuchos
192 
193 
194 
200 namespace std {
201  // C++-style output functions for Superludist complex types
202  ostream& operator<<(ostream& out, const SLUD::Z::doublecomplex z);
203 
205 }
206 #endif // HAVE_TEUCHOS_COMPLEX
207 
208 
209 
210 namespace Amesos2 {
211 
212 template <class, class> class Superludist;
213 
214 /* Specialize the Amesos2::TypeMap struct for SuperLU_DIST types
215  *
216  * \cond Superludist_type_specializations
217  */
218 template <>
219 struct TypeMap<Superludist,double>
220 {
221  static const SLUD::Dtype_t dtype = SLUD::SLU_D;
222  typedef double type;
223  typedef double magnitude_type;
224  typedef SLUD::D::LUstruct_t LUstruct_t;
225  typedef SLUD::D::SOLVEstruct_t SOLVEstruct_t;
226 };
227 
228 #ifdef HAVE_TEUCHOS_COMPLEX
229 template <>
230 struct TypeMap<Superludist,std::complex<double> >
231 {
232  static const SLUD::Dtype_t dtype = SLUD::SLU_Z;
233  typedef SLUD::Z::doublecomplex type;
234  typedef double magnitude_type;
235  typedef SLUD::Z::LUstruct_t LUstruct_t;
236  typedef SLUD::Z::SOLVEstruct_t SOLVEstruct_t;
237 };
238 
239  // It probably won't happen, but what if someone does create a
240  // matrix or multivector with the SuperLU_DIST doublecomplex type
241  // directly?
242 template <>
243 struct TypeMap<Superludist,SLUD::Z::doublecomplex>
244 {
245  static const SLUD::Dtype_t dtype = SLUD::SLU_Z;
246  typedef SLUD::Z::doublecomplex type;
247  typedef double magnitude_type;
248  typedef SLUD::Z::LUstruct_t LUstruct_t;
249  typedef SLUD::Z::SOLVEstruct_t SOLVEstruct_t;
250 };
251 
252 #endif // HAVE_TEUCHOS_COMPLEX
253 
254 /* \endcond Superludist_type_specializations */
255 
256 
257 } // end namespace Amesos2
258 
259 #endif // AMESOS2_SUPERLUDIST_TYPEMAP_HPP
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Definition: Amesos2_Cholmod_TypeMap.hpp:92
Definition: Amesos2_Superludist_TypeMap.hpp:69