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
43namespace Blas
44{
45
46extern "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
57static inline void Dcopy(const int &n,
59 const int &incx,
61 const int &incy)
62{
63 ASSERTL1(static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
64 "Array out of bounds");
65 ASSERTL1(static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
66 "Array out of bounds");
67
68 F77NAME(dcopy)(n, &x[0], incx, &y[0], incy);
69}
70
71/// \brief BLAS level 1: y = alpha \a x plus \a y
72static inline void Daxpy(const int &n, const double &alpha,
74 const int &incx,
76 const int &incy)
77{
78 ASSERTL1(static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
79 "Array out of bounds");
80 ASSERTL1(static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
81 "Array out of bounds");
82
83 F77NAME(daxpy)(n, alpha, &x[0], incx, &y[0], incy);
84}
85
86/// \brief BLAS level 1: output = \f$ x^T y \f$
87static inline double Ddot(const int &n,
89 const int &incx,
91 const int &incy)
92{
93 return F77NAME(ddot)(n, &x[0], incx, &y[0], incy);
94}
95} // namespace Blas
96#endif // NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLASARRAY_HPP
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
#define F77NAME(x)
Fortran routines need an underscore.
Definition: TransF77.hpp:46
Definition: Blas.hpp:43
void F77NAME() daxpy(const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy)
double F77NAME() ddot(const int &n, const double *x, const int &incx, const double *y, const int &incy)
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:128
void F77NAME() dcopy(const int &n, const double *x, const int &incx, 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:163
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:135