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