Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
\( \alpha M \cdot x + \beta y\) and \( x^T M y \) More...
Namespaces | |
namespace | dg::blas2 |
BLAS Level 2 routines. | |
Functions | |
template<class ContainerType1 , class MatrixType , class ContainerType2 > | |
get_value_type< MatrixType > | dg::blas2::dot (const ContainerType1 &x, const MatrixType &m, const ContainerType2 &y) |
\( x^T M y\); Binary reproducible general dot product More... | |
template<class MatrixType , class ContainerType > | |
get_value_type< MatrixType > | dg::blas2::dot (const MatrixType &m, const ContainerType &x) |
\( x^T M x\); Binary reproducible general dot product More... | |
template<class MatrixType , class ContainerType1 , class ContainerType2 > | |
void | dg::blas2::symv (get_value_type< ContainerType1 > alpha, MatrixType &&M, const ContainerType1 &x, get_value_type< ContainerType1 > beta, ContainerType2 &y) |
\( y = \alpha M x + \beta y\) More... | |
template<class MatrixType , class ContainerType1 , class ContainerType2 > | |
void | dg::blas2::symv (MatrixType &&M, const ContainerType1 &x, ContainerType2 &y) |
\( y = M x\) More... | |
template<class MatrixType , class ContainerType1 , class ContainerType2 > | |
void | dg::blas2::gemv (get_value_type< ContainerType1 > alpha, MatrixType &&M, const ContainerType1 &x, get_value_type< ContainerType1 > beta, ContainerType2 &y) |
\( y = \alpha M x + \beta y \); (alias for symv) More... | |
template<class MatrixType , class ContainerType1 , class ContainerType2 > | |
void | dg::blas2::gemv (MatrixType &&M, const ContainerType1 &x, ContainerType2 &y) |
\( y = M x\); (alias for symv) More... | |
template<class Stencil , class ContainerType , class ... ContainerTypes> | |
void | dg::blas2::parallel_for (Stencil f, unsigned N, ContainerType &&x, ContainerTypes &&... xs) |
\( f(i, x_0, x_1, ...)\ \forall i\); Customizable and generic for loop More... | |
template<class FunctorType , class MatrixType , class ContainerType1 , class ContainerType2 > | |
void | dg::blas2::stencil (FunctorType f, MatrixType &&M, const ContainerType1 &x, ContainerType2 &y) |
\( F(M, x, y)\) More... | |
template<class MatrixType , class AnotherMatrixType > | |
void | dg::blas2::transfer (const MatrixType &x, AnotherMatrixType &y) |
\( y = x\); Generic way to copy and/or convert a Matrix type to a different Matrix type More... | |
\( \alpha M \cdot x + \beta y\) and \( x^T M y \)
|
inline |
\( x^T M y\); Binary reproducible general dot product
This routine computes the scalar product defined by the symmetric positive definite matrix M
\[ x^T M y = \sum_{i,j=0}^{N-1} x_i M_{ij} y_j \]
This code snippet demonstrates how to discretize and compute the norm of a function on a shared memory system
Inf
or NaN
or the product of the input numbers reaches Inf
or Nan
then the behaviour is undefined and the function may throw. See dg::ISNFINITE and dg::ISNSANE in that case dg::exblas
library and works for single and double precision.x | Left input |
m | The diagonal Matrix. |
y | Right input (may alias x ) |
x
and y
are vectors of containers and m
is not, then we sum the results of dg::blas2::dot( x[i], m, y[i])
nan
MatrixType | MatrixType has to have a category derived from AnyVectorTag and must be compatible with the ContainerTypes |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( x^T M x\); Binary reproducible general dot product
Equivalent to dg::blas2::dot( x,m,x)
\[ x^T M x = \sum_{i,j=0}^{N-1} x_i M_{ij} x_j \]
m | The diagonal Matrix |
x | Right input |
x
is a vector of containers and m
is not, then we sum the results of dg::blas2::dot( m, x[i])
dg::blas2::dot( x, m, x)
; which should be prefered because it looks more explicit MatrixType | MatrixType has to have a category derived from AnyVectorTag and must be compatible with the ContainerTypes |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( y = \alpha M x + \beta y \); (alias for symv)
This routine computes
\[ y = \alpha M x + \beta y \]
where \( M\) is a matrix (or functor that is called like M(alpha,x,beta,y)
). There is nothing that prevents you from making the matrix M
non-symmetric or even non-linear. In this sense the term "symv" (symmetrix-Matrix-Vector multiplication) is misleading. For better code readability we introduce aliases: dg::blas2::gemv
(general Matrix-Vector multiplication) and dg::apply
(general, possibly non-linear functor application).
This code snippet demonstrates how to derive a function on a device
alpha | A Scalar |
M | The Matrix. |
x | input vector |
beta | A Scalar |
y | contains the solution on output (may not alias x ) |
y
may not alias x
, the only exception is if MatrixType
has the AnyVectorTag
MatrixType | Any class for which a specialization of TensorTraits exists and defines a tensor_category derived from AnyMatrixTag . Furthermore, any functor/lambda type with signature void operator()( const ContainerType0&, ContainerType1&) . For example
SelfMadeMatrixTag only those blas2 functions that have a corresponding member function in the Matrix class (e.g. symv( const ContainerType0&, ContainerType1&); ) can be called. If a Container has the RecursiveVectorTag , then the matrix is applied to each of the elements unless the type has the SelfMadeMatrixTag or is a Functor type. |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( y = M x\); (alias for symv)
This routine computes
\[ y = M x \]
where \( M\) is a matrix (or functor that is called like M(x,y)
). There is nothing that prevents you from making the matrix M
non-symmetric or even non-linear. In this sense the term "symv" (symmetrix-Matrix-Vector multiplication) is misleading. For better code readability we introduce aliases: dg::blas2::gemv
(general Matrix-Vector multiplication) and dg::apply
(general, possibly non-linear functor application)
This code snippet demonstrates how to derive a function on a device
M | The Matrix. |
x | input vector |
y | contains the solution on output (may not alias x ) |
y
may not alias x
, the only exception is if MatrixType
has the AnyVectorTag
and ContainerType1
==ContainerType2
MatrixType | Any class for which a specialization of TensorTraits exists and defines a tensor_category derived from AnyMatrixTag . Furthermore, any functor/lambda type with signature void operator()( const ContainerType0&, ContainerType1&) . For example
SelfMadeMatrixTag only those blas2 functions that have a corresponding member function in the Matrix class (e.g. symv( const ContainerType0&, ContainerType1&); ) can be called. If a Container has the RecursiveVectorTag , then the matrix is applied to each of the elements unless the type has the SelfMadeMatrixTag or is a Functor type. |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( f(i, x_0, x_1, ...)\ \forall i\); Customizable and generic for loop
dg::blas1::subroutine
This routine loops over an arbitrary user-defined "loop body" functor f
with an arbitrary number of arguments \( x_s\) elementwise
\[ f(i, x_{0}, x_{1}, ...) \]
where i
iterates from 0
to a given size N
. The order of iterations is undefined. It is equivalent to the following
With this function very general for-loops can be parallelized like for example a forward finite difference:
dg::blas1::subroutine
to non-trivial parallelization tasks. However, this comes at a price: this function only works for containers with the dg::SharedVectorTag
and sclar types. The reason it cannot work for MPI is that the stencil (and thus the communication pattern) is unkown. However, it can serve as an important building block for other parallel functions like dg::blas2::parallel_for
. kokkos::parallel_for
of the Kokkos library.f | the loop body |
N | the total number of iterations in the for loop |
x | the first argument |
xs | other arguments |
Stencil | a function or functor with an arbitrary number of arguments and no return type; The first argument is an unsigned (the loop iteration), afterwards takes a const_pointer_type argument (const pointer to first element in vector) for each input argument in the call and a pointer_type argument (pointer to first element in vector) for each output argument. Scalars are forwarded "as is" scalar_type . Stencil must be callable on the device in use. In particular, with CUDA it must be a functor (not a function) and its signature must contain the __device__ specifier. (s.a. DG_DEVICE) |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the SharedVectorTag and AnyPolicyTag . Among others
|
|
inline |
\( F(M, x, y)\)
This routine calls
\[ F(i, [M], x, y) \]
for all \( i \in [0,N[\), where N is the number of rows in M, using dg::blas2::parallel_for
, where [M] depends on the matrix type:
Possible shared memory implementation
Other matrix types have not yet been implemented.
dg::blas2::parallel_for
). dg::blas2::parallel_for
to MPI vectors at the cost of having to encode the communication stencil in the matrix M
and only one vector argumentf | The filter function is called like f(i, m.row_offsets_ptr, m.column_indices_ptr, m.values_ptr, x_ptr, y_ptr) |
M | The Matrix. |
x | input vector |
y | contains the solution on output (may not alias x ) |
FunctorType | A type that is callable void operator()( unsigned, pointer, [m_pointers], const_pointer) For GPU vector the functor must be callable on the device. |
MatrixType | So far only one of the cusp::csr_matrix types and their MPI variants dg::MPIDistMat<cusp::csr_matrix, Comm> are allowed |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( y = \alpha M x + \beta y\)
This routine computes
\[ y = \alpha M x + \beta y \]
where \( M\) is a matrix (or functor that is called like M(alpha,x,beta,y)
). There is nothing that prevents you from making the matrix M
non-symmetric or even non-linear. In this sense the term "symv" (symmetrix-Matrix-Vector multiplication) is misleading. For better code readability we introduce aliases: dg::blas2::gemv
(general Matrix-Vector multiplication) and dg::apply
(general, possibly non-linear functor application).
This code snippet demonstrates how to derive a function on a device
alpha | A Scalar |
M | The Matrix. |
x | input vector |
beta | A Scalar |
y | contains the solution on output (may not alias x ) |
y
may not alias x
, the only exception is if MatrixType
has the AnyVectorTag
MatrixType | Any class for which a specialization of TensorTraits exists and defines a tensor_category derived from AnyMatrixTag . Furthermore, any functor/lambda type with signature void operator()( const ContainerType0&, ContainerType1&) . For example
SelfMadeMatrixTag only those blas2 functions that have a corresponding member function in the Matrix class (e.g. symv( const ContainerType0&, ContainerType1&); ) can be called. If a Container has the RecursiveVectorTag , then the matrix is applied to each of the elements unless the type has the SelfMadeMatrixTag or is a Functor type. |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( y = M x\)
This routine computes
\[ y = M x \]
where \( M\) is a matrix (or functor that is called like M(x,y)
). There is nothing that prevents you from making the matrix M
non-symmetric or even non-linear. In this sense the term "symv" (symmetrix-Matrix-Vector multiplication) is misleading. For better code readability we introduce aliases: dg::blas2::gemv
(general Matrix-Vector multiplication) and dg::apply
(general, possibly non-linear functor application)
This code snippet demonstrates how to derive a function on a device
M | The Matrix. |
x | input vector |
y | contains the solution on output (may not alias x ) |
y
may not alias x
, the only exception is if MatrixType
has the AnyVectorTag
and ContainerType1
==ContainerType2
MatrixType | Any class for which a specialization of TensorTraits exists and defines a tensor_category derived from AnyMatrixTag . Furthermore, any functor/lambda type with signature void operator()( const ContainerType0&, ContainerType1&) . For example
SelfMadeMatrixTag only those blas2 functions that have a corresponding member function in the Matrix class (e.g. symv( const ContainerType0&, ContainerType1&); ) can be called. If a Container has the RecursiveVectorTag , then the matrix is applied to each of the elements unless the type has the SelfMadeMatrixTag or is a Functor type. |
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
\( y = x\); Generic way to copy and/or convert a Matrix type to a different Matrix type
e.g. from CPU to GPU, or double to float, etc.
MatrixType | Any class for which a specialization of TensorTraits exists and defines a tensor_category derived from AnyMatrixTag . Furthermore, any functor/lambda type with signature void operator()( const ContainerType0&, ContainerType1&) . For example
SelfMadeMatrixTag only those blas2 functions that have a corresponding member function in the Matrix class (e.g. symv( const ContainerType0&, ContainerType1&); ) can be called. If a Container has the RecursiveVectorTag , then the matrix is applied to each of the elements unless the type has the SelfMadeMatrixTag or is a Functor type. |
AnotherMatrix | Another Matrix type |
x | source |
y | sink |
This code snippet demonstrates how to derive a function on a device