Nektar++
BlasArray.hpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File BlasArray.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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: wrapper of functions around standard BLAS routines
32 // using Array's as calling arguments
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLASARRAY_HPP
37 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLASARRAY_HPP
38 
41 
42 // Translations for using Fortran version of blas
43 namespace Blas
44 {
45 
46  extern "C"
47  {
48  // -- BLAS Level 1:
49  void F77NAME(dcopy) (const int& n, const double *x, const int& incx,
50  double *y, const int& incy);
51  void F77NAME(daxpy) (const int& n, const double& alpha, const double *x,
52  const int& incx, const double *y, const int& incy);
53  double F77NAME(ddot) (const int& n, const double *x, const int& incx,
54  const double *y, const int& incy);
55  }
56 
57  static inline void Dcopy (const int& n, const Nektar::Array <Nektar::OneD, const double> &x, const int& incx, Nektar::Array<Nektar::OneD,double> &y, const int& incy)
58  {
59  ASSERTL1(static_cast<unsigned int>(n*incx) <= x.num_elements()+x.GetOffset(),"Array out of bounds");
60  ASSERTL1(static_cast<unsigned int>(n*incy) <= y.num_elements()+y.GetOffset(),"Array out of bounds");
61 
62  F77NAME(dcopy)(n,&x[0],incx,&y[0],incy);
63  }
64 
65  /// \brief BLAS level 1: y = alpha \a x plus \a y
66  static inline void Daxpy (const int& n, const double& alpha, const Nektar::Array <Nektar::OneD,const double> &x, const int& incx, Nektar::Array<Nektar::OneD,double> &y, const int& incy)
67  {
68  ASSERTL1(static_cast<unsigned int>(n*incx) <= x.num_elements()+x.GetOffset(),"Array out of bounds");
69  ASSERTL1(static_cast<unsigned int>(n*incy) <= y.num_elements()+y.GetOffset(),"Array out of bounds");
70 
71  F77NAME(daxpy)(n,alpha,&x[0],incx,&y[0],incy);
72  }
73 
74  /// \brief BLAS level 1: output = \f$ x^T y \f$
75  static inline double Ddot (const int& n, const Nektar::Array <Nektar::OneD,const double> &x, const int& incx,
76  const Nektar::Array <Nektar::OneD,const double> &y, const int& incy)
77  {
78  return F77NAME(ddot)(n,&x[0],incx,&y[0],incy);
79  }
80 }
81 #endif // NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLASARRAY_HPP
void F77NAME() dcopy(const int &n, const double *x, const int &incx, double *y, const int &incy)
#define F77NAME(x)
Fortran routines need an underscore.
Definition: TransF77.hpp:46
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)
static double Ddot(const int &n, const double *x, const int &incx, const double *y, const int &incy)
BLAS level 1: output = .
Definition: Blas.hpp:140
Definition: Blas.hpp:44
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
static void Daxpy(const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy)
BLAS level 1: y = alpha x plus y.
Definition: Blas.hpp:110
static void Dcopy(const int &n, const double *x, const int &incx, double *y, const int &incy)
BLAS level 1: Copy x to y.
Definition: Blas.hpp:103