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