Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_PardisoMKL_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 
44 
56 #ifndef AMESOS2_PARDISOMKL_TYPEMAP_HPP
57 #define AMESOS2_PARDISOMKL_TYPEMAP_HPP
58 
59 #ifdef HAVE_TEUCHOS_COMPLEX
60 #include <complex>
61 #endif
62 
63 #include <mkl_types.h>
64 #include <mkl_dss.h>
65 
66 #include <Teuchos_as.hpp>
67 #ifdef HAVE_TEUCHOS_COMPLEX
68 #include <Teuchos_SerializationTraits.hpp>
69 #endif
70 
71 #include "Amesos2_TypeMap.hpp"
72 
73 namespace Amesos2{
74  namespace PMKL {
75  #undef _MKL_TYPES_H_
76  #include <mkl_types.h>
77 
78  #undef __MKL_DSS_H
79  #include <mkl_dss.h>
80 
81  //Update JDB 6.25.15
82  //MKL has changed _INTEGER_t to deprecated
83  //MKL has changed _INTEGER_t to define from typedef
84  #undef _INTEGER_t
85  typedef MKL_INT _INTEGER_t;
86  } // end namespace PMKL
87 } // end namespace Amesos2
88 
89 
90 /* ==================== Conversion ====================
91  *
92  * Define here, in the Teuchos namespace, any conversions between
93  * commonly used date types and the solver-specific data types. Use
94  * template specializations of the Teuchos::ValueTypeConversionTraits
95  * class.
96  */
97 #ifdef HAVE_TEUCHOS_COMPLEX
98 namespace Teuchos {
99 
100  template <typename TypeFrom>
101  class ValueTypeConversionTraits<Amesos2::PMKL::_MKL_Complex8, TypeFrom>
102  {
103  public:
104  static Amesos2::PMKL::_MKL_Complex8 convert( const TypeFrom t )
105  { // adapt conversion as necessary
106  Amesos2::PMKL::_MKL_Complex8 ret;
107  ret.real = Teuchos::as<float>(t.real());
108  ret.imag = Teuchos::as<float>(t.imag());
109  return( ret );
110  }
111 
112  static Amesos2::PMKL::_MKL_Complex8 safeConvert( const TypeFrom t )
113  { // adapt conversion as necessary
114  Amesos2::PMKL::_MKL_Complex8 ret;
115  ret.real = Teuchos::as<float>(t.real());
116  ret.imag = Teuchos::as<float>(t.imag());
117  return( ret );
118  }
119  };
120 
121 
122  template <typename TypeFrom>
123  class ValueTypeConversionTraits<Amesos2::PMKL::_DOUBLE_COMPLEX_t, TypeFrom>
124  {
125  public:
126  static Amesos2::PMKL::_DOUBLE_COMPLEX_t convert( const TypeFrom t )
127  { // adapt conversion as necessary
128  Amesos2::PMKL::_DOUBLE_COMPLEX_t ret;
129  ret.r = Teuchos::as<double>(t.real());
130  ret.i = Teuchos::as<double>(t.imag());
131  return( ret );
132  }
133 
134  static Amesos2::PMKL::_DOUBLE_COMPLEX_t safeConvert( const TypeFrom t )
135  { // adapt conversion as necessary
136  Amesos2::PMKL::_DOUBLE_COMPLEX_t ret;
137  ret.r = Teuchos::as<double>(t.real());
138  ret.i = Teuchos::as<double>(t.imag());
139  return( ret );
140  }
141  };
142 
143 
144  // Also convert *from* New_Solver types
145  template <typename TypeTo>
146  class ValueTypeConversionTraits<TypeTo, Amesos2::PMKL::_MKL_Complex8>
147  {
148  public:
149  static TypeTo convert( const Amesos2::PMKL::_MKL_Complex8 t )
150  { // adapt conversion as necessary
151  typedef typename TypeTo::value_type value_type;
152  value_type ret_r = Teuchos::as<value_type>( t.real );
153  value_type ret_i = Teuchos::as<value_type>( t.imag );
154  return ( TypeTo( ret_r, ret_i ) );
155  }
156 
157  static TypeTo safeConvert( const Amesos2::PMKL::_MKL_Complex8 t )
158  { // adapt conversion as necessary
159  typedef typename TypeTo::value_type value_type;
160  value_type ret_r = Teuchos::as<value_type>( t.real );
161  value_type ret_i = Teuchos::as<value_type>( t.imag );
162  return ( TypeTo( ret_r, ret_i ) );
163  }
164  };
165 
166 
167  template <typename TypeTo>
168  class ValueTypeConversionTraits<TypeTo, Amesos2::PMKL::_DOUBLE_COMPLEX_t>
169  {
170  public:
171  static TypeTo convert( const Amesos2::PMKL::_DOUBLE_COMPLEX_t t )
172  {
173  typedef typename TypeTo::value_type value_type;
174  value_type ret_r = Teuchos::as<value_type>( t.r );
175  value_type ret_i = Teuchos::as<value_type>( t.i );
176  return ( TypeTo( ret_r, ret_i ) );
177  }
178 
179  // No special checks for safe Convert
180  static TypeTo safeConvert( const Amesos2::PMKL::_DOUBLE_COMPLEX_t t )
181  {
182  typedef typename TypeTo::value_type value_type;
183  value_type ret_r = Teuchos::as<value_type>( t.r );
184  value_type ret_i = Teuchos::as<value_type>( t.i );
185  return ( TypeTo( ret_r, ret_i ) );
186  }
187  };
188 
190 
191 } // end namespace Teuchos
192 #endif
193 
194 namespace Amesos2 {
195 
196  // forward declaration due to circular reference
197  template <class, class> class PardisoMKL;
198 
199  /* Specialize the Amesos::TypeMap struct for PardisoMKL types.
200  *
201  * Additional nested types may be added without harm. For an example, look at
202  * Amesos2_Superlu_TypeMap.hpp
203  */
204 
205  template <>
206  struct TypeMap<PardisoMKL,float>
207  {
208  typedef PMKL::_REAL_t type;
209  typedef PMKL::_REAL_t magnitude_type;
210  };
211 
212 
213  template <>
214  struct TypeMap<PardisoMKL,double>
215  {
216  typedef PMKL::_DOUBLE_PRECISION_t type;
217  typedef PMKL::_DOUBLE_PRECISION_t magnitude_type;
218  };
219 
220 #ifdef HAVE_TEUCHOS_COMPLEX
221 
222  /*
223  * We map the std complex types to the appropriate PardisoMKL complex
224  * types.
225  */
226 
227  template <>
228  struct TypeMap<PardisoMKL,std::complex<float> >
229  {
230  typedef PMKL::_MKL_Complex8 type;
231  typedef PMKL::_REAL_t magnitude_type;
232  };
233 
234 
235  template <>
236  struct TypeMap<PardisoMKL,std::complex<double> >
237  {
238  typedef PMKL::_DOUBLE_COMPLEX_t type;
239  typedef PMKL::_DOUBLE_PRECISION_t magnitude_type;
240  };
241 
242 
243  template <>
244  struct TypeMap<PardisoMKL,PMKL::_MKL_Complex8>
245  {
246  typedef PMKL::_MKL_Complex8 type;
247  typedef PMKL::_REAL_t magnitude_type;
248  };
249 
250 
251  template <>
252  struct TypeMap<PardisoMKL,PMKL::_DOUBLE_COMPLEX_t>
253  {
254  typedef PMKL::_DOUBLE_COMPLEX_t type;
255  typedef PMKL::_DOUBLE_PRECISION_t magnitude_type;
256  };
257 #endif // HAVE_TEUCHOS_COMPLEX
258 
259  template <>
260  struct TypeMap<PardisoMKL,int>
261  {
262  typedef PMKL::_INTEGER_t type;
263  //typedef int type;
264  };
265 
266  template <>
267  struct TypeMap<PardisoMKL,long long int>
268  {
269  typedef long long int type;
270  };
271 
272  /*
273  * We check whether the size of long int is bigger than an int. If
274  * it is, then long int should be the same size as a long long int,
275  * so we can safely promote. Otherwise, long int will probably be
276  * the same size as int, and we can safely treat it as such.
277  */
278  template <>
279  struct TypeMap<PardisoMKL,long int>
280  {
281  typedef std::conditional_t<
282  sizeof(int) < sizeof(long int),
283  TypeMap<PardisoMKL,long long int>::type,
284  TypeMap<PardisoMKL,int>::type > type;
285  };
286 
287 } // end namespace Amesos
288 
289 #endif // AMESOS2_PARDISOMKL_TYPEMAP_HPP