Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superlu_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
54#ifndef AMESOS2_SUPERLU_TYPEMAP_HPP
55#define AMESOS2_SUPERLU_TYPEMAP_HPP
56
57#include <functional>
58#ifdef HAVE_TEUCHOS_COMPLEX
59#include <complex>
60#endif
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/* The SuperLU comples headers file only need to be included if
70 complex has been enabled in Teuchos. In addition we only need to
71 define the conversion and printing functions if complex has been
72 enabled. */
73namespace SLU {
74
75typedef int int_t;
76
77extern "C" {
78
79#undef __SUPERLU_SUPERMATRIX
80#include "supermatrix.h" // for Dtype_t declaration
81
82#ifdef HAVE_TEUCHOS_COMPLEX
83namespace C {
84#undef __SUPERLU_SCOMPLEX
85#undef SCOMPLEX_INCLUDE
86#include "slu_scomplex.h" // single-precision complex data type definitions
87}
88
89namespace Z {
90#undef __SUPERLU_DCOMPLEX
91#undef DCOMPLEX_INCLUDE
92#include "slu_dcomplex.h" // double-precision complex data type definitions
93}
94#endif // HAVE_TEUCHOS_COMPLEX
95
96} // end extern "C"
97
98} // end namespace SLU
99
100#ifdef HAVE_TEUCHOS_COMPLEX
101
102/* ==================== Conversion ==================== */
103namespace Teuchos {
104
112template <>
113class ValueTypeConversionTraits<SLU::C::complex, Kokkos::complex<float>>
114{
115public:
116 static SLU::C::complex convert( const Kokkos::complex<float> t ) {
117 SLU::C::complex ret;
118 ret.r = t.real();
119 ret.i = t.imag();
120 return( ret );
121 }
122
123 static SLU::C::complex safeConvert( const Kokkos::complex<float> t ) {
124 SLU::C::complex ret;
125 ret.r = t.real();
126 ret.i = t.imag();
127 return( ret );
128 }
129};
130
131template <>
132class ValueTypeConversionTraits<SLU::Z::doublecomplex, Kokkos::complex<double>>
133{
134public:
135 static SLU::Z::doublecomplex convert( const Kokkos::complex<double> t ) {
136 SLU::Z::doublecomplex ret;
137 ret.r = t.real();
138 ret.i = t.imag();
139 return( ret );
140 }
141
142 static SLU::Z::doublecomplex safeConvert( const Kokkos::complex<double> t ) {
143 SLU::Z::doublecomplex ret;
144 ret.r = t.real();
145 ret.i = t.imag();
146 return( ret );
147 }
148};
149
150// Also convert from SLU types
151
152template <>
153class ValueTypeConversionTraits<Kokkos::complex<float>, SLU::C::complex>
154{
155public:
156 static Kokkos::complex<float> convert( const SLU::C::complex t ) {
157 return ( Kokkos::complex<float>( t.r, t.i ) );
158 }
159
160 static Kokkos::complex<float> safeConvert( const SLU::C::complex t ) {
161 return ( Kokkos::complex<float>( t.r, t.i ) );
162 }
163};
164
165template <>
166class ValueTypeConversionTraits<Kokkos::complex<double>, SLU::Z::doublecomplex>
167{
168public:
169 static Kokkos::complex<double> convert( const SLU::Z::doublecomplex t ) {
170 return ( Kokkos::complex<double>( t.r, t.i ) );
171 }
172
173 static Kokkos::complex<double> safeConvert( const SLU::Z::doublecomplex t ) {
174 return ( Kokkos::complex<double>( t.r, t.i ) );
175 }
176};
177
179
180} // end namespace Teuchos
181
182#endif // HAVE_TEUCHOS_COMPLEX
183
184namespace Amesos2 {
185
186template <class, class> class Superlu;
187
188/* Specialize the Amesos2::TypeMap struct for Superlu types
189 *
190 * \cond Superlu_type_specializations
191 */
192template <>
193struct TypeMap<Superlu,float>
194{
195 static SLU::Dtype_t dtype;
196 typedef float convert_type;
197 typedef float type;
198 typedef float magnitude_type;
199};
200
201
202template <>
203struct TypeMap<Superlu,double>
204{
205 static SLU::Dtype_t dtype;
206 typedef double convert_type;
207 typedef double type;
208 typedef double magnitude_type;
209};
210
211
212#ifdef HAVE_TEUCHOS_COMPLEX
213
214template <>
215struct TypeMap<Superlu,std::complex<float> >
216{
217 static SLU::Dtype_t dtype;
218 typedef SLU::C::complex convert_type; // to create array before calling superlu
219 typedef Kokkos::complex<float> type;
220 typedef float magnitude_type;
221};
222
223
224template <>
225struct TypeMap<Superlu,std::complex<double> >
226{
227 static SLU::Dtype_t dtype;
228 typedef SLU::Z::doublecomplex convert_type; // to create array before calling superlu
229 typedef Kokkos::complex<double> type;
230 typedef double magnitude_type;
231};
232
233
234template <>
235struct TypeMap<Superlu,Kokkos::complex<float> >
236{
237 static SLU::Dtype_t dtype;
238 typedef SLU::C::complex convert_type; // to create array before calling superlu
239 typedef Kokkos::complex<float> type;
240 typedef float magnitude_type;
241};
242
243
244template <>
245struct TypeMap<Superlu,Kokkos::complex<double> >
246{
247 static SLU::Dtype_t dtype;
248 typedef SLU::Z::doublecomplex convert_type; // to create array before calling superlu
249 typedef Kokkos::complex<double> type;
250 typedef double magnitude_type;
251};
252
253
254#endif // HAVE_TEUCHOS_COMPLEX
255
256/* \endcond Superlu_type_specializations */
257
258
259} // end namespace Amesos2
260
261#endif // AMESOS2_SUPERLU_TYPEMAP_HPP