Nektar++
Blas.hpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File Blas.hpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: wrapper of functions around standard BLAS routines
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLAS_HPP
37 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLAS_HPP
38 
41 
42 // Translations for using Fortran version of blas
43 namespace Blas
44 {
45  extern "C"
46  {
47  // -- BLAS Level 1:
48  void F77NAME(dcopy) (const int& n, const double *x, const int& incx,
49  double *y, const int& incy);
50  void F77NAME(daxpy) (const int& n, const double& alpha, const double *x,
51  const int& incx, const double *y, const int& incy);
52  void F77NAME(dswap) (const int& n, double *x, const int& incx,
53  double *y, const int& incy);
54  void F77NAME(dscal) (const int& n, const double& alpha, double *x,
55  const int& incx);
56  void F77NAME(drot) (const int& n, double *x, const int& incx,
57  double *y, const int& incy, const double& c,
58  const double& s);
59  double F77NAME(ddot) (const int& n, const double *x, const int& incx,
60  const double *y, const int& incy);
61  double F77NAME(dnrm2) (const int& n, const double *x, const int& incx);
62  double F77NAME(dasum) (const int& n, const double *x, const int& incx);
63  int F77NAME(idamax)(const int& n, const double *x, const int& incx);
64 
65  // -- BLAS level 2
66  void F77NAME(dgemv) (const char& trans, const int& m,
67  const int& n, const double& alpha,
68  const double* a, const int& lda,
69  const double* x, const int& incx,
70  const double& beta, double* y, const int& incy);
71 
72  void F77NAME(dgbmv) (const char& trans, const int& m,
73  const int& n, const int& kl, const int& ku,
74  const double& alpha,
75  const double* a, const int& lda,
76  const double* x, const int& incx,
77  const double& beta, double* y, const int& incy);
78 
79  void F77NAME(dtpmv) (const char& uplo, const char& trans, const char& diag,
80  const int& n, const double* ap, double* x, const int& incx);
81 
82  void F77NAME(dspmv) (const char& trans, const int& n, const double& alpha,
83  const double* a, const double* x, const int& incx,
84  const double& beta, double* y, const int& incy);
85 
86  void F77NAME(dsbmv) (const char& uplo, const int& m,
87  const int& k, const double& alpha,
88  const double* a, const int& lda,
89  const double* x, const int& incx,
90  const double& beta, double* y, const int& incy);
91 
92  // -- BLAS level 3:
93  void F77NAME(dgemm) (const char& trans, const char& transb,
94  const int& m1, const int& n,
95  const int& k, const double& alpha,
96  const double* a, const int& lda,
97  const double* b, const int& ldb,
98  const double& beta, double* c, const int& ldc);
99  }
100 
101 #ifdef NEKTAR_USING_BLAS
102  /// \brief BLAS level 1: Copy \a x to \a y
103  static inline void Dcopy (const int& n, const double *x, const int& incx,
104  double *y, const int& incy)
105  {
106  F77NAME(dcopy)(n,x,incx,y,incy);
107  }
108 
109  /// \brief BLAS level 1: y = alpha \a x plus \a y
110  static inline void Daxpy (const int& n, const double& alpha, const double *x,
111  const int& incx, const double *y, const int& incy)
112  {
113  F77NAME(daxpy)(n,alpha,x,incx,y,incy);
114  }
115 
116 
117  /// \brief BLAS level 1: Swap \a x with \a y
118  static inline void Dswap (const int& n,double *x, const int& incx,
119  double *y, const int& incy)
120  {
121  F77NAME(dswap)(n,x,incx,y,incy);
122  }
123 
124  /// \brief BLAS level 1: x = alpha \a x
125  static inline void Dscal (const int& n, const double& alpha, double *x,
126  const int& incx)
127  {
128  F77NAME(dscal)(n,alpha,x,incx);
129  }
130 
131  /// \brief BLAS level 1: Plane rotation by c = cos(theta), s = sin(theta)
132  static inline void Drot (const int& n, double *x, const int& incx,
133  double *y, const int& incy, const double& c,
134  const double& s)
135  {
136  F77NAME(drot)(n,x,incx,y,incy,c,s);
137  }
138 
139  /// \brief BLAS level 1: output = \f$ x^T y \f$
140  static inline double Ddot (const int& n, const double *x, const int& incx,
141  const double *y, const int& incy)
142  {
143  return F77NAME(ddot)(n,x,incx,y,incy);
144  }
145 
146  // \brief BLAS level 1: output = \f$ ||x||_2 \f$
147 
148  static inline double Dnrm2 (const int& n, const double *x, const int& incx)
149  {
150  return F77NAME(dnrm2)(n,x,incx);
151  }
152 
153  /// \brief BLAS level 1: output = \f$ ||x||_1 \f$
154  static inline double Dasum (const int& n, const double *x, const int& incx)
155  {
156  return F77NAME(dasum)(n,x,incx);
157  }
158 
159  /// \brief BLAS level 1: output = 1st value where \f$ |x[i]| = max |x|_1 \f$
160  /// Note it is modified to return a value between (0,n-1) as per
161  /// the standard C convention
162  static inline int Idamax (const int& n, const double *x, const int& incx)
163  {
164  return F77NAME(idamax)(n,x,incx) -1;
165  }
166 
167  /// \brief BLAS level 2: Matrix vector multiply y = A \e x where A[m x n]
168  static inline void Dgemv (const char& trans, const int& m, const int& n,
169  const double& alpha, const double* a, const int& lda,
170  const double* x, const int& incx, const double& beta,
171  double* y, const int& incy)
172  {
173  F77NAME(dgemv) (trans,m,n,alpha,a,lda,x,incx,beta,y,incy);
174  }
175 
176  static inline void Dgbmv (const char& trans, const int& m,
177  const int& n, const int& kl, const int& ku,
178  const double& alpha,
179  const double* a, const int& lda,
180  const double* x, const int& incx,
181  const double& beta, double* y, const int& incy)
182  {
183  F77NAME(dgbmv) (trans, m, n, kl, ku, alpha, a, lda, x, incx, beta, y, incy);
184  }
185 
186 
187  static inline void Dtpmv(const char& uplo, const char& trans, const char& diag,
188  const int& n, const double* ap, double* x, const int& incx)
189  {
190  F77NAME(dtpmv) (uplo, trans, diag, n, ap, x, incx);
191  }
192 
193  /// \brief BLAS level 2: Matrix vector multiply y = A \e x where A
194  /// is symmetric packed
195  static inline void Dspmv (const char& trans, const int& n, const double& alpha,
196  const double* a, const double* x, const int& incx,
197  const double& beta, double* y, const int& incy)
198  {
199  F77NAME(dspmv) (trans,n,alpha,a,x,incx,beta,y,incy);
200  }
201 
202  static inline void Dsbmv (const char& uplo, const int& m, const int& k,
203  const double& alpha, const double* a, const int& lda,
204  const double* x, const int& incx, const double& beta,
205  double* y, const int& incy)
206  {
207  F77NAME(dsbmv) (uplo,m,k,alpha,a,lda,x,incx,beta,y,incy);
208  }
209 
210 
211  /// \brief BLAS level 3: Matrix-matrix multiply C = A x B where A[m x n],
212  /// B[n x k], C[m x k]
213  static inline void Dgemm (const char& transa, const char& transb, const int& m,
214  const int& n, const int& k, const double& alpha,
215  const double* a, const int& lda, const double* b,
216  const int& ldb, const double& beta, double* c,
217  const int& ldc)
218  {
219  F77NAME(dgemm) (transa,transb,m,n,k,alpha,a,lda,b,ldb,beta,c,ldc);
220  }
221 
222  // \brief Wrapper to mutliply two (row major) matrices together C =
223  // a*A*B + b*C
224  static inline void Cdgemm(const int M, const int N, const int K, const double a,
225  const double *A, const int ldA, const double * B, const int ldB,
226  const double b, double *C, const int ldC)
227  {
228  Dgemm('N','N',N,M,K,a,B,N,A,K,b,C,N) ;
229  }
230 #endif //NEKTAR_USING_BLAS
231 }
232 #endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLAS_HPP
233 
234 /***
235 $Log: Blas.hpp,v $
236 Revision 1.6 2008/04/06 05:55:11 bnelson
237 Changed ConstArray to Array<const>
238 
239 Revision 1.5 2008/02/28 09:57:08 sherwin
240 Added array version of some routines
241 
242 Revision 1.4 2007/09/02 23:33:04 bnelson
243 *** empty log message ***
244 
245 Revision 1.3 2007/08/29 22:35:21 bnelson
246 Added upper triangular matrix time vector.
247 
248 Revision 1.2 2007/06/17 22:54:23 bnelson
249 Fixed the row-major matrix multiplication wrapper function.
250 
251 Revision 1.1 2007/04/03 03:59:24 bnelson
252 Moved Lapack.hpp, Blas.hpp, Transf77.hpp to LinearAlgebra
253 
254 Revision 1.3 2007/02/04 00:15:40 bnelson
255 *** empty log message ***
256 
257 Revision 1.2 2006/06/01 13:44:28 kirby
258 *** empty log message ***
259 
260 Revision 1.1 2006/06/01 11:07:52 kirby
261 *** empty log message ***
262 
263 Revision 1.1 2006/05/04 18:57:41 kirby
264 *** empty log message ***
265 
266 Revision 1.4 2006/02/26 21:13:45 bnelson
267 Fixed a variety of compiler errors caused by updates to the coding standard.
268 
269 Revision 1.3 2006/02/15 08:07:15 sherwin
270 
271 Put codes into standard although have not yet been compiled
272 
273 Revision 1.2 2006/02/12 21:51:42 sherwin
274 
275 Added licence
276 
277 Revision 1.1 2006/02/12 15:06:12 sherwin
278 
279 Changed .h files to .hpp
280 
281 **/
void F77NAME() dscal(const int &n, const double &alpha, double *x, const int &incx)
void F77NAME() dgbmv(const char &trans, const int &m, const int &n, const int &kl, const int &ku, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
void F77NAME() dgemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
int F77NAME() idamax(const int &n, const double *x, const int &incx)
double F77NAME() dnrm2(const int &n, const double *x, const int &incx)
void F77NAME() dcopy(const int &n, const double *x, const int &incx, double *y, const int &incy)
void F77NAME() drot(const int &n, double *x, const int &incx, double *y, const int &incy, const double &c, const double &s)
#define F77NAME(x)
Fortran routines need an underscore.
Definition: TransF77.hpp:47
void F77NAME() dsbmv(const char &uplo, const int &m, const int &k, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
void F77NAME() dswap(const int &n, double *x, const int &incx, double *y, const int &incy)
double F77NAME() ddot(const int &n, const double *x, const int &incx, const double *y, const int &incy)
void F77NAME() daxpy(const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy)
double F77NAME() dasum(const int &n, const double *x, const int &incx)
T Ddot(int n, const Array< OneD, const T > &w, const int incw, const Array< OneD, const T > &x, const int incx, const Array< OneD, const int > &y, const int incy)
Definition: VmathArray.hpp:434
void F77NAME() dtpmv(const char &uplo, const char &trans, const char &diag, const int &n, const double *ap, double *x, const int &incx)
void F77NAME() dgemm(const char &trans, const char &transb, const int &m1, const int &n, const int &k, const double &alpha, const double *a, const int &lda, const double *b, const int &ldb, const double &beta, double *c, const int &ldc)
void F77NAME() dspmv(const char &trans, const int &n, const double &alpha, const double *a, const double *x, const int &incx, const double &beta, double *y, const int &incy)
Definition: Blas.hpp:43