Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
Modules | |
All TensorTraits specialisations | |
Classes | |
struct | dg::AnyPolicyTag |
Execution Policy base class. More... | |
struct | dg::NoPolicyTag |
Indicate that a type does not have an execution policy. More... | |
struct | dg::AnyMatrixTag |
tensor_category base class More... | |
struct | dg::NotATensorTag |
Indicate that a type is not a tensor. More... | |
At the heart of the dispatch system lies the dg::TensorTraits
class that specifies how a type T
behaves in the respective functions though a tag system defined by the tensor_category
tag and the execution_policy
tag. Per default it looks like
The values for tensor_category
are either dg::NotATensorTag
or (a class derived from) dg::AnyMatrixTag
, while the values for execution_policy
are either dg::NoPolicyTag
or (a class derived from) dg::AnyPolicyTag
. Any type T
assumes the above default values for value_type
, tensor_category
and execution_policy
unless a specialisation exists for that type (see All TensorTraits specialisations for a full list). We define the following nomenclature
typename dg::TensorTraits<T>::tensor_category
derives from dg::AnyScalarTag
typename dg::TensorTraits<T>::tensor_category
derives from dg::AnyVectorTag
typename dg::TensorTraits<T>::tensor_category
derives from dg::AnyMatrixTag
typename dg::TensorTraits<T>::execution_policy
derives from dg::AnyPolicyTag
, The execution policy is trivial if it is dg::AnyPolicyTag
typename dg::TensorTraits<T>::value_type
is non-voiddg::AnyVectorTag
, Two execution policies are compatible if they are equal or if at least one of them is trivial.When dispatching level 1 functions we distinguish between three classes of functions: trivially parallel (dg::blas1::subroutine
and related dg::blas1
functions), global communication (dg::blas1::dot
and dg::blas2::dot
) and local communication (dg::blas2::symv
).
The execution of dg::blas1::subroutine
with a Functor called routine
(and all related dg::blas1
functions) is equivalent to the following:
routine
routine
routine
and returndg::SharedVectorTag
, check execution policy and dispatch to respective implementation (The implementation just loops over all elements in the vectors and applies the routine
)dg::MPIVectorTag
, access the underlying data and recursively call dg::blas1::subroutine
(and start again at 1)dg::RecursiveVectorTag
, loop over all elements and recursively call dg::blas1::subroutine
for all elements (and start again at 1)The execution of dg::blas1::dot
and dg::blas2::dot
is equivalent to the following:
dg::SharedVectorTag
, check execution policy and dispatch to respective implementation (The implementation multiplies and accumulates all elements in the vectors). Return the result.dg::MPIVectorTag
, assert that the vector MPI-communicators are congruent
(same process group, different context) or ident
(same process group, same context). Then, access the underlying data and recursively call dot
(and start again at 1). Accumulate the result among participating processes and return.dg::RecursiveVectorTag
, loop over all elements and recursively call dot
for all elements (and start again at 1). Accumulate the results and return.In the execution of the dg::blas2::symv
(and its aliases dg::blas2::gemv
and dg::apply
) each matrix type has individual prerequisites and execution paths depending on its tensor_category
. We can identify some general rules:
dg::NotATensorTag
(any type has this tag by default unless it is overwritten by a specialization of dg::TensorTraits
) then the compiler assumes that the type is a functor type and immediately forwards all parameters to the operator()
member and none of the following appliesdg::SelfMadeMatrixTag
tensor category, then all parameters are immediately forwarded to the symv
member function. No asserts are performed and none of the following applies.dg::RecursiveVectorTag
tensor category, then dg::blas2::symv
is equivalent to dg::blas1::pointwiseDot
dg::RecursiveVectorTag
and the tensor category of the Matrix is not, then the dg::blas2::symv
is recursively called with the Matrix on all elements of the Vectors.