|
Amesos2 - Direct Sparse Solver Interfaces
Version of the Day
|
00001 // @HEADER 00002 // 00003 // *********************************************************************** 00004 // 00005 // Amesos2: Templated Direct Sparse Solver Package 00006 // Copyright 2011 Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // 00042 // @HEADER 00043 00053 #ifndef AMESOS2_KLU2_TYPEMAP_HPP 00054 #define AMESOS2_KLU2_TYPEMAP_HPP 00055 00056 #include <functional> 00057 #ifdef HAVE_TEUCHOS_COMPLEX 00058 #include <complex> 00059 #endif 00060 00061 #include <Teuchos_as.hpp> 00062 #ifdef HAVE_TEUCHOS_COMPLEX 00063 #include <Teuchos_SerializationTraits.hpp> 00064 #endif 00065 00066 #include "Amesos2_TypeMap.hpp" 00067 00068 00069 /* The KLU2 comples headers file only need to be included if 00070 complex has been enabled in Teuchos. In addition we only need to 00071 define the conversion and printing functions if complex has been 00072 enabled. */ 00073 // TODO 00074 namespace KLU2 { 00075 00076 typedef int int_t; 00077 00078 #include "klu2_ext.hpp" // for Dtype_t declaration 00079 00080 // Declare and specialize a std::binary_funtion class for 00081 // multiplication of SuperLU types 00082 //template <typename slu_scalar_t, typename slu_mag_t> 00083 //struct slu_mult {}; 00084 00085 // This specialization handles the generic case were the scalar and 00086 // magnitude types are double or float. 00087 //template <typename T> 00088 //struct slu_mult<T,T> : std::multiplies<T> {}; 00089 00090 #ifdef HAVE_TEUCHOS_COMPLEX 00091 00092 // For namespace/macro reasons, we prefix our variables with amesos_* 00093 //template <> 00094 //struct slu_mult<C::complex,float> 00095 //: std::binary_function<C::complex,float,C::complex> { 00096 //C::complex operator()(C::complex amesos_c, float amesos_f) { 00097 //C::complex amesos_cr; 00098 //cs_mult(&amesos_cr, &amesos_c, amesos_f); // cs_mult is a macro, so no namespacing 00099 //return( amesos_cr ); 00100 //} 00101 //}; 00102 00103 //template <> 00104 //struct slu_mult<C::complex,C::complex> 00105 //: std::binary_function<C::complex,C::complex,C::complex> { 00106 //C::complex operator()(C::complex amesos_c1, C::complex amesos_c2) { 00107 //C::complex amesos_cr; 00108 //cc_mult(&amesos_cr, &amesos_c1, &amesos_c2); // cc_mult is a macro, so no namespacing 00109 //return( amesos_cr ); 00110 //} 00111 //}; 00112 00113 //template <> 00114 //struct slu_mult<Z::doublecomplex,double> 00115 //: std::binary_function<Z::doublecomplex,double,Z::doublecomplex> { 00116 //Z::doublecomplex operator()(Z::doublecomplex amesos_z, double amesos_d) { 00117 //Z::doublecomplex amesos_zr; 00118 //zd_mult(&amesos_zr, &amesos_z, amesos_d); // zd_mult is a macro, so no namespacing 00119 //return( amesos_zr ); 00120 //} 00121 //}; 00122 00123 //template <> 00124 //struct slu_mult<Z::doublecomplex,Z::doublecomplex> 00125 //: std::binary_function<Z::doublecomplex,Z::doublecomplex,Z::doublecomplex> { 00126 //Z::doublecomplex operator()(Z::doublecomplex amesos_z1, Z::doublecomplex amesos_z2) { 00127 //Z::doublecomplex amesos_zr; 00128 //zz_mult(&amesos_zr, &amesos_z1, &amesos_z2); // zz_mult is a macro, so no namespacing 00129 //return( amesos_zr ); 00130 //} 00131 //}; 00132 00133 #endif // HAVE_TEUCHOS_COMPLEX 00134 } // end namespace KLU 00135 #ifdef HAVE_TEUCHOS_COMPLEX 00136 00137 /* ==================== Conversion ==================== */ 00138 namespace Teuchos { 00139 00150 /*template <typename TypeFrom> 00151 class ValueTypeConversionTraits<SLU::C::complex, TypeFrom> 00152 { 00153 public: 00154 static SLU::C::complex convert( const TypeFrom t ) 00155 { 00156 SLU::C::complex ret; 00157 ret.r = Teuchos::as<float>(t.real()); 00158 ret.i = Teuchos::as<float>(t.imag()); 00159 return( ret ); 00160 } 00161 00162 static SLU::C::complex safeConvert( const TypeFrom t ) 00163 { 00164 SLU::C::complex ret; 00165 ret.r = Teuchos::as<float>(t.real()); 00166 ret.i = Teuchos::as<float>(t.imag()); 00167 return( ret ); 00168 } 00169 }; 00170 00171 00172 template <typename TypeFrom> 00173 class ValueTypeConversionTraits<SLU::Z::doublecomplex, TypeFrom> 00174 { 00175 public: 00176 static SLU::Z::doublecomplex convert( const TypeFrom t ) 00177 { 00178 SLU::Z::doublecomplex ret; 00179 ret.r = Teuchos::as<double>(t.real()); 00180 ret.i = Teuchos::as<double>(t.imag()); 00181 return( ret ); 00182 } 00183 00184 static SLU::Z::doublecomplex safeConvert( const TypeFrom t ) 00185 { 00186 SLU::Z::doublecomplex ret; 00187 ret.r = Teuchos::as<double>(t.real()); 00188 ret.i = Teuchos::as<double>(t.imag()); 00189 return( ret ); 00190 } 00191 }; 00192 00193 00194 // Also convert from SLU types 00195 template <typename TypeTo> 00196 class ValueTypeConversionTraits<TypeTo, SLU::C::complex> 00197 { 00198 public: 00199 static TypeTo convert( const SLU::C::complex t ) 00200 { 00201 typedef typename TypeTo::value_type value_type; 00202 value_type ret_r = Teuchos::as<value_type>( t.r ); 00203 value_type ret_i = Teuchos::as<value_type>( t.i ); 00204 return ( TypeTo( ret_r, ret_i ) ); 00205 } 00206 00207 // No special checks for safe Convert 00208 static TypeTo safeConvert( const SLU::C::complex t ) 00209 { 00210 typedef typename TypeTo::value_type value_type; 00211 value_type ret_r = Teuchos::as<value_type>( t.r ); 00212 value_type ret_i = Teuchos::as<value_type>( t.i ); 00213 return ( TypeTo( ret_r, ret_i ) ); 00214 } 00215 }; 00216 00217 00218 template <typename TypeTo> 00219 class ValueTypeConversionTraits<TypeTo, SLU::Z::doublecomplex> 00220 { 00221 public: 00222 static TypeTo convert( const SLU::Z::doublecomplex t ) 00223 { 00224 typedef typename TypeTo::value_type value_type; 00225 value_type ret_r = Teuchos::as<value_type>( t.r ); 00226 value_type ret_i = Teuchos::as<value_type>( t.i ); 00227 return ( TypeTo( ret_r, ret_i ) ); 00228 } 00229 00230 // No special checks for safe Convert 00231 static TypeTo safeConvert( const SLU::Z::doublecomplex t ) 00232 { 00233 typedef typename TypeTo::value_type value_type; 00234 value_type ret_r = Teuchos::as<value_type>( t.r ); 00235 value_type ret_i = Teuchos::as<value_type>( t.i ); 00236 return ( TypeTo( ret_r, ret_i ) ); 00237 } 00238 }; 00239 00240 template <typename Ordinal> 00241 class SerializationTraits<Ordinal,SLU::C::complex> 00242 : public DirectSerializationTraits<Ordinal,SLU::C::complex> 00243 {}; 00244 00245 template <typename Ordinal> 00246 class SerializationTraits<Ordinal,SLU::Z::doublecomplex> 00247 : public DirectSerializationTraits<Ordinal,SLU::Z::doublecomplex> 00248 {}; 00249 00251 */ 00252 00253 } // end namespace Teuchos 00254 00255 // C++-style output functions for Superlu complex types 00256 /*namespace std { 00257 ostream& operator<<(ostream& out, const SLU::Z::doublecomplex z); 00258 00259 ostream& operator<<(ostream& out, const SLU::C::complex c); 00260 }*/ 00261 00262 #endif // HAVE_TEUCHOS_COMPLEX 00263 00264 00265 namespace Amesos2 { 00266 00267 template <class, class> class KLU2; 00268 00269 /* Specialize the Amesos2::TypeMap struct for KLU2 types 00270 * TODO: Mostly dummy assignments as KLU2 is templated. Remove if possible. 00271 * 00272 * \cond KLU2_type_specializations 00273 */ 00274 template <> 00275 struct TypeMap<KLU2,float> 00276 { 00277 static float dtype; 00278 typedef float type; 00279 typedef float magnitude_type; 00280 }; 00281 00282 00283 template <> 00284 struct TypeMap<KLU2,double> 00285 { 00286 static double dtype; 00287 typedef double type; 00288 typedef double magnitude_type; 00289 }; 00290 00291 00292 #ifdef HAVE_TEUCHOS_COMPLEX 00293 00294 template <> 00295 struct TypeMap<KLU2,std::complex<float> > 00296 { 00297 static std::complex<float> dtype; 00298 typedef std::complex<float> type; 00299 typedef float magnitude_type; 00300 }; 00301 00302 00303 template <> 00304 struct TypeMap<KLU2,std::complex<double> > 00305 { 00306 static std::complex<double> dtype; 00307 typedef std::complex<double> type; 00308 typedef double magnitude_type; 00309 }; 00310 00311 00312 //template <> 00313 //struct TypeMap<KLU2,SLU::C::complex> 00314 //{ 00315 //static SLU::Dtype_t dtype; 00316 //typedef SLU::C::complex type; 00317 //typedef float magnitude_type; 00318 //}; 00319 00320 00321 //template <> 00322 //struct TypeMap<KLU2,SLU::Z::doublecomplex> 00323 //{ 00324 //static SLU::Dtype_t dtype; 00325 //typedef SLU::Z::doublecomplex type; 00326 //typedef double magnitude_type; 00327 //}; 00328 00329 00330 #endif // HAVE_TEUCHOS_COMPLEX 00331 00332 /* \endcond KLU2_type_specializations */ 00333 00334 00335 } // end namespace Amesos2 00336 00337 #endif // AMESOS2_SUPERLU_TYPEMAP_HPP
1.7.6.1