wrapper.h
00001 /* Copyright (C) 2007  Martin Förg, Jan Clauberg
00002 
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  * 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016  *
00017  * Contact:
00018  *   martin.o.foerg@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef wrapper_h
00023 #define wrapper_h
00024 
00025 #ifndef HAVE_LIBMKL_INTEL_LP64
00026 #ifndef CBLAS_ENUM_DEFINED_H
00027    #define CBLAS_ENUM_DEFINED_H
00028    enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
00029    enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
00030                          AtlasConj=114};
00031    enum CBLAS_UPLO  {CblasUpper=121, CblasLower=122};
00032    enum CBLAS_DIAG  {CblasNonUnit=131, CblasUnit=132};
00033    enum CBLAS_SIDE  {CblasLeft=141, CblasRight=142};
00034 #endif
00035 #define CBLAS_INDEX int
00036 
00037 #ifndef ATLAS_ENUM_H
00038    #define ATLAS_ENUM_H
00039    #define ATLAS_ORDER CBLAS_ORDER
00040       #define AtlasRowMajor CblasRowMajor
00041       #define AtlasColMajor CblasColMajor
00042    #define ATLAS_TRANS CBLAS_TRANSPOSE
00043       #define AtlasNoTrans CblasNoTrans
00044       #define AtlasTrans CblasTrans
00045       #define AtlasConjTrans CblasConjTrans
00046    #define ATLAS_UPLO CBLAS_UPLO
00047       #define AtlasUpper CblasUpper
00048       #define AtlasLower CblasLower
00049    #define ATLAS_DIAG CBLAS_DIAG
00050       #define AtlasNonUnit CblasNonUnit
00051       #define AtlasUnit CblasUnit
00052    #define ATLAS_SIDE CBLAS_SIDE
00053       #define AtlasLeft  CblasLeft
00054       #define AtlasRight CblasRight
00055 #endif
00056 #else
00057 #include "mkl_cblas.h"
00058 #endif
00059 
00060 #include <complex>
00061 
00062 typedef std::complex<double> doublecomplex;
00063 
00064 #if defined(HAVE_LIBBLAS)
00065 namespace fmatvec {
00066   void dscal(const int N, const double alpha, double *X, const int incX) ;
00067   void dgemm(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE TransA,
00068                  const CBLAS_TRANSPOSE TransB, const int M, const int N,
00069                  const int K, const double alpha, const double *A,
00070                  const int lda, const double *B, const int ldb,
00071                  const double beta, double *C, const int ldc);
00072   void dsymm(const CBLAS_ORDER Order, const CBLAS_SIDE Side,
00073                  const CBLAS_UPLO Uplo, const int M, const int N,
00074                  const double alpha, const double *A, const int lda,
00075                  const double *B, const int ldb, const double beta,
00076                  double *C, const int ldc);
00077   void daxpy(const int N, const double alpha, const double *X,
00078                  const int incX, double *Y, const int incY);
00079   void dcopy(const int N, const double *X, const int incX,
00080                  double *Y, const int incY);
00081   void dgemv(const CBLAS_ORDER Order,
00082                  const CBLAS_TRANSPOSE TransA, const int M, const int N,
00083                  const double alpha, const double *A, const int lda,
00084                  const double *X, const int incX, const double beta,
00085                  double *Y, const int incY);
00086   void dsymv(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo,
00087                  const int N, const double alpha, const double *A,
00088                  const int lda, const double *X, const int incX,
00089                  const double beta, double *Y, const int incY);
00090   double ddot(const int N, const double *X, const int incX,
00091                   const double *Y, const int incY);
00092   double dasum(const int N, const double *X, const int incX);
00093   CBLAS_INDEX idamax(const int N, const double *X, const int incX);
00094   double dnrm2(const int N, const double *X, const int incX);
00095   int dgesv(const CBLAS_ORDER Order, const int N, const int NRHS,
00096                   double *A, const int lda, int *ipiv,
00097                   double *B, const int ldb);
00098   int zgesv(const CBLAS_ORDER Order, const int N, const int NRHS,
00099                   doublecomplex *A, const int lda, int *ipiv,
00100                   doublecomplex *B, const int ldb);
00101   int dgetrs(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE Trans,
00102     const int N, const int NRHS, const double *A, const int lda,
00103     const int *ipiv, double *B, const int ldb);
00104   int dgetrf(const CBLAS_ORDER Order, const int M, const int N,
00105                    double *A, const int lda, int *ipiv);
00106   int dgetri(const CBLAS_ORDER Order, const int N, double *A,
00107                    const int lda, const int *ipiv);
00108   int dpotrf(const ATLAS_ORDER Order, const ATLAS_UPLO Uplo, const int N, double *A, const int lda);
00109   int dpotri(const ATLAS_ORDER Order, const ATLAS_UPLO Uplo,
00110                    const int N, double *A, const int lda);
00111   int dposv(const ATLAS_ORDER Order, const ATLAS_UPLO Uplo,
00112                   const int N, const int NRHS, double *A, const int lda,
00113                   double *B, const int ldb);
00114   int dpotrs(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo,
00115                    const int N, const int NRHS, const double *A, const int lda,
00116                    double *B, const int ldb);
00117 }
00118 #endif
00119 
00120 #if defined(HAVE_LIBATLAS)
00121 namespace fmatvec {
00122 
00123 extern "C" {
00124 #include "cblas.h"
00125 #include "clapack.h"
00126 }
00127 
00128 #define dscal  cblas_dscal
00129 #define dcopy  cblas_dcopy
00130 #define ddot   cblas_ddot
00131 #define dnrm2  cblas_dnrm2
00132 #define dasum  cblas_dasum
00133 #define idamax cblas_idamax
00134 #define daxpy  cblas_daxpy
00135 #define dgemv  cblas_dgemv
00136 #define dsymv  cblas_dsymv
00137 #define dgemm  cblas_dgemm
00138 #define dsymm  cblas_dsymm
00139 
00140 #define dgesv  clapack_dgesv
00141 #define zgesv  clapack_zgesv
00142 #define dgetrs clapack_dgetrs
00143 #define dgetrf clapack_dgetrf
00144 #define dgetri clapack_dgetri
00145 #define dpotrf clapack_dpotrf
00146 #define dpotri clapack_dpotri
00147 #define dpotrs clapack_dpotrs
00148 #define dposv  clapack_dposv
00149 
00150 }
00151 #endif
00152 
00153 #if defined(HAVE_LIBMKL_INTEL_LP64)
00154 extern "C" {
00155 #include "mkl_cblas.h"
00156 #include "mkl_lapacke.h"
00157 #include "mkl_lapack.h"  
00158 }
00159 
00160 #define dscal  cblas_dscal
00161 #define dcopy  cblas_dcopy
00162 #define ddot   cblas_ddot
00163 #define dnrm2  cblas_dnrm2
00164 #define dasum  cblas_dasum
00165 #define idamax cblas_idamax
00166 #define daxpy  cblas_daxpy
00167 #define dgemv  cblas_dgemv
00168 #define dsymv  cblas_dsymv
00169 #define dgemm  cblas_dgemm
00170 #define dsymm  cblas_dsymm
00171 
00172 #define dgesv  LAPACKE_dgesv
00173 #define zgesv  LAPACKE_zgesv
00174 #define dgetrs LAPACKE_dgetrs
00175 #define dgetrf LAPACKE_dgetrf
00176 #define dgetri LAPACKE_dgetri
00177 #define dpotrf LAPACKE_dpotrf
00178 #define dpotri LAPACKE_dpotri
00179 #define dpotrs LAPACKE_dpotrs
00180 #define dposv  LAPACKE_dposv
00181 
00182 #endif
00183 
00184 namespace fmatvec {
00185 
00186 #ifndef HAVE_LIBMKL_INTEL_LP64
00187   int dsyevx(const char jobz, const char range, const CBLAS_UPLO cuplo, const int n, double *a, const int lda, const double vl, const double vu, const int il, const int iu, const double abstol, const int *m, double *w, double *z, const int ldz);
00188 #else
00189    int dsyevx(const char jobz, const char range, const CBLAS_UPLO cuplo, const int n, double *a, const int lda, const double vl, const double vu, const int il, const int iu, const double abstol, int *m, double *w, double *z, const int ldz); 
00190 #endif
00191 
00192   int dgels( const CBLAS_TRANSPOSE ctr, const int m, const int n, const int nhrs, double* a, const int lda, double* b, const int ldb);
00193 
00194   int dgelss(const int m, const int n, const int nrhs, double *a, const int lda, double *b, const int ldb, const double rcond);
00195 
00196   int dgeev(const char jobvl, const char jobvr, const int n, double *a, const int lda, double *wr, double *wi, double *vl, const int ldvl, double *vr, const int ldvr);
00197 
00198   int dsygv(const int itype, const char jobz, const char uplo, const int n, double *a, const int lda, double *b, const int ldb, double *w);
00199   
00200   int dgesvd(const char jobu, const char jobvt, const int m, const int n, double *a, const int lda, double *s, double *u, const int ldu, double *vt, const int ldvt);
00201 
00202   int dsyev(const char jobz, const char ul, const int n, double *a, const int lda, double *w);
00203 
00204   double dlange(const char norm , const int m, const int n, const double* a, const int lda);
00205 }
00206 #endif