Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Superlu_FunctionMap.hpp
Go to the documentation of this file.
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_SUPERLU_FUNCTIONMAP_HPP
00054 #define AMESOS2_SUPERLU_FUNCTIONMAP_HPP
00055 
00056 #ifdef HAVE_TEUCHOS_COMPLEX
00057 #include <complex>
00058 #endif
00059 
00060 #include "Amesos2_FunctionMap.hpp"
00061 #include "Amesos2_Superlu_TypeMap.hpp"
00062 
00063 
00064 /* External definitions of the Superlu functions
00065  *
00066  * Note that we do include the "slu_*defs.h" files provided for each
00067  * data-type.  This produces linker warnings, but keeps us from
00068  * including SuperLU code in our own code (even if only extern
00069  * declarations, which would eliminate linker warnings).  This is
00070  * because there are several declarations (as of SuperLU 4.1) across
00071  * these headers which conflict with each other in C linkage.  All of
00072  * the conflicting functions, on the other hand, we do not care about.
00073  */
00074 namespace SLU {
00075 
00076   extern "C" {
00077     typedef int int_t;
00078 #include "supermatrix.h"
00079 #include "slu_util.h"
00080 
00081     namespace S {               // single-precision real definitions
00082 #include "slu_sdefs.h"
00083     }
00084 
00085     namespace D {               // double-precision real definitions
00086 #include "slu_ddefs.h"
00087     }
00088 
00089 #ifdef HAVE_TEUCHOS_COMPLEX
00090     namespace C {              // single-precision complex definitions
00091 #include "slu_cdefs.h"
00092     }
00093 
00094     namespace Z {              // double-precision complex definitions
00095 #include "slu_zdefs.h"
00096     }
00097 #endif  // HAVE_TEUCHOS_COMPLEX
00098 
00099   } // end extern "C"
00100 
00101 } // end namespace SLU
00102 
00103 
00104 namespace Amesos2 {
00105 
00106   /* ==================== Specializations ====================
00107    *
00108    * \cond Superlu_function_specializations
00109    */
00110 
00134   template <>
00135   struct FunctionMap<Superlu,float>
00136   {
00137     typedef TypeMap<Superlu,float> type_map;
00138 
00142     static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
00143           int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
00144           SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
00145           SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
00146           float* rcond, float* ferr, float* berr, SLU::mem_usage_t* mem_usage,
00147           SLU::SuperLUStat_t* stat, int* info)
00148     {
00149       SLU::S::sgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
00150          lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
00151     }
00152 
00172     static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
00173           int relax, int panel_size, int* etree, void* work,
00174           int lwork, int* perm_c, int* perm_r, SLU::SuperMatrix* L,
00175           SLU::SuperMatrix* U, SLU::SuperLUStat_t* stat, int* info)
00176     {
00177       SLU::S::sgstrf(options, AC, relax, panel_size, etree,
00178          work, lwork, perm_c, perm_r, L, U, stat, info);
00179     }
00180 
00184     static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, 
00185               int nnz, type_map::type* nzval, int* rowind, int* colptr, 
00186               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00187     {
00188       SLU::S::sCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00189              stype, dtype, mtype);
00190     }
00191 
00195     static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, 
00196               int nnz, type_map::type* nzval, int* rowind, int* colptr,
00197               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00198     {
00199       SLU::S::sCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00200              stype, dtype, mtype);
00201     }
00202 
00203 
00212     static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
00213             type_map::type* x, int ldx, SLU::Stype_t stype,
00214             SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00215     {
00216       SLU::S::sCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
00217     }
00218 
00222     static void gsequ(SLU::SuperMatrix* A, float* R, float* C,
00223           float* rowcnd, float* colcnd, float* amax, int* info)
00224     {
00225       SLU::S::sgsequ(A, R, C, rowcnd, colcnd, amax, info);
00226     }
00227 
00242     static void laqgs(SLU::SuperMatrix* A, float* R, float* C,
00243           float rowcnd, float colcnd, float amax, char* equed)
00244     {
00245       SLU::S::slaqgs(A, R, C, rowcnd, colcnd, amax, equed);
00246     }
00247   };
00248 
00249 
00250   template <>
00251   struct FunctionMap<Superlu,double>
00252   {
00253     typedef TypeMap<Superlu,double> type_map;
00254 
00255     static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
00256           int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
00257           SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
00258           SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
00259           double* rcond, double* ferr, double* berr, SLU::mem_usage_t* mem_usage,
00260           SLU::SuperLUStat_t* stat, int* info)
00261     {
00262       SLU::D::dgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
00263          lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
00264     }
00265 
00266     static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
00267           int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
00268           int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
00269           SLU::SuperLUStat_t* stat, int* info)
00270     {
00271       SLU::D::dgstrf(options, AC, relax, panel_size, etree,
00272          work, lwork, perm_c, perm_r, L, U, stat, info);
00273     }
00274 
00275     static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, 
00276               int nnz, type_map::type* nzval, int* rowind, int* colptr, 
00277               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00278     {
00279       SLU::D::dCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00280              stype, dtype, mtype);
00281     }
00282 
00283     static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, 
00284               int nnz, type_map::type* nzval, int* rowind, int* colptr, 
00285               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00286     {
00287       SLU::D::dCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00288              stype, dtype, mtype);
00289     }
00290 
00291     static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, 
00292             int n, type_map::type* x, int ldx, SLU::Stype_t stype, 
00293             SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00294     {
00295       SLU::D::dCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
00296     }
00297 
00298     static void gsequ(SLU::SuperMatrix* A, double* R, double* C,
00299           double* rowcnd, double* colcnd, double* amax, int* info)
00300     {
00301       SLU::D::dgsequ(A, R, C, rowcnd, colcnd, amax, info);
00302     }
00303 
00304     static void laqgs(SLU::SuperMatrix* A, double* R, double* C,
00305           double rowcnd, double colcnd, double amax, char* equed)
00306     {
00307       SLU::D::dlaqgs(A, R, C, rowcnd, colcnd, amax, equed);
00308     }
00309 
00310   };
00311 
00312 
00313 #ifdef HAVE_TEUCHOS_COMPLEX
00314 
00315   /* The specializations for Teuchos::as<> for SLU::complex and
00316    * SLU::doublecomplex are provided in Amesos2_Superlu_Type.hpp
00317    */
00318   template <>
00319   struct FunctionMap<Superlu,SLU::C::complex>
00320   {
00321     static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
00322           int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
00323           SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
00324           SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
00325           float* rcond, float* ferr, float* berr, SLU::mem_usage_t* mem_usage,
00326           SLU::SuperLUStat_t* stat, int* info)
00327     {
00328       SLU::C::cgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
00329          lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
00330     }
00331 
00332     static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
00333           int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
00334           int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
00335           SLU::SuperLUStat_t* stat, int* info)
00336     {
00337       SLU::C::cgstrf(options, AC, relax, panel_size, etree,
00338          work, lwork, perm_c, perm_r, L, U, stat, info);
00339     }
00340 
00341     static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
00342               SLU::C::complex* nzval, int* rowind, int* colptr,
00343               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00344     {
00345       SLU::C::cCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00346              stype, dtype, mtype);
00347     }
00348 
00349     static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
00350               SLU::C::complex* nzval, int* rowind, int* colptr,
00351               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00352     {
00353       SLU::C::cCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00354              stype, dtype, mtype);
00355     }
00356 
00357     static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
00358             SLU::C::complex* x, int ldx, SLU::Stype_t stype,
00359             SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00360     {
00361       SLU::C::cCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
00362     }
00363 
00364     static void gsequ(SLU::SuperMatrix* A, float* R, float* C,
00365           float* rowcnd, float* colcnd, float* amax, int* info)
00366     {
00367       SLU::C::cgsequ(A, R, C, rowcnd, colcnd, amax, info);
00368     }
00369 
00370     static void laqgs(SLU::SuperMatrix* A, float* R, float* C,
00371           float rowcnd, float colcnd, float amax, char* equed)
00372     {
00373       SLU::C::claqgs(A, R, C, rowcnd, colcnd, amax, equed);
00374     }
00375   };
00376 
00377 
00378   template <>
00379   struct FunctionMap<Superlu,SLU::Z::doublecomplex>
00380   {
00381     static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
00382           int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
00383           SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
00384           SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
00385           double* rcond, double* ferr, double* berr, SLU::mem_usage_t* mem_usage,
00386           SLU::SuperLUStat_t* stat, int* info)
00387     {
00388       SLU::Z::zgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
00389          lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
00390     }
00391 
00392     static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
00393           int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
00394           int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
00395           SLU::SuperLUStat_t* stat, int* info)
00396     {
00397       SLU::Z::zgstrf(options, AC, relax, panel_size, etree,
00398          work, lwork, perm_c, perm_r, L, U, stat, info);
00399     }
00400 
00401     static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
00402               SLU::Z::doublecomplex* nzval, int* rowind, int* colptr,
00403               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00404     {
00405       SLU::Z::zCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00406              stype, dtype, mtype);
00407 
00408       TEUCHOS_TEST_FOR_EXCEPTION( A == NULL,
00409         std::runtime_error,
00410         "Supermatrix A not initialized properly!");
00411     }
00412 
00413 
00414     static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
00415               SLU::Z::doublecomplex* nzval, int* rowind, int* colptr,
00416               SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00417     {
00418       SLU::Z::zCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
00419              stype, dtype, mtype);
00420 
00421       TEUCHOS_TEST_FOR_EXCEPTION( A == NULL,
00422         std::runtime_error,
00423         "Supermatrix A not initialized properly!");
00424     }
00425 
00426     static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
00427             SLU::Z::doublecomplex* x, int ldx, SLU::Stype_t stype,
00428             SLU::Dtype_t dtype, SLU::Mtype_t mtype)
00429     {
00430       SLU::Z::zCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
00431     }
00432 
00433     static void gsequ(SLU::SuperMatrix* A, double* R, double* C,
00434           double* rowcnd, double* colcnd, double* amax, int* info)
00435     {
00436       SLU::Z::zgsequ(A, R, C, rowcnd, colcnd, amax, info);
00437     }
00438 
00439     static void laqgs(SLU::SuperMatrix* A, double* R, double* C,
00440           double rowcnd, double colcnd, double amax, char* equed)
00441     {
00442       SLU::Z::zlaqgs(A, R, C, rowcnd, colcnd, amax, equed);
00443     }
00444   };
00445 #endif  // HAVE_TEUCHOS_COMPLEX
00446 
00447   /* \endcond Superlu_function_specializations */
00448 
00449 
00450 } // end namespace Amesos2
00451 
00452 #endif  // AMESOS2_SUPERLU_FUNCTIONMAP_HPP