Discontinuous Galerkin Library
#include "dg/algorithm.h"
dg::View< ThrustVector > Struct Template Reference

A vector view class, usable in dg functions. More...

Public Types

using iterator = std::conditional_t< std::is_const< ThrustVector >::value, typename ThrustVector::const_iterator, typename ThrustVector::iterator >
 
using const_iterator = typename ThrustVector::const_iterator
 
using pointer = std::conditional_t< std::is_const< ThrustVector >::value, typename ThrustVector::const_pointer, typename ThrustVector::pointer >
 
using const_pointer = typename ThrustVector::const_pointer
 

Public Member Functions

 View (void)
 Initialize empty view. More...
 
template<class OtherView >
 View (OtherView &src)
 Construct from another View or Vector. More...
 
template<class InputIterator >
 View (InputIterator data, unsigned size)
 Construct view from pointer and size. More...
 
template<class InputIterator >
void construct (InputIterator data, unsigned size)
 Construct view from pointer and size. More...
 
pointer data () const
 Constant Reference of the pointer. More...
 
iterator begin () const
 Iterator to the beginning. More...
 
const_iterator cbegin () const
 const Iterator to the beginning More...
 
iterator end () const
 Iterator to the end. More...
 
const_iterator cend () const
 const Iterator to the end More...
 
unsigned size () const
 Get the size. More...
 
void swap (View &src)
 Swap pointer and size with another View. More...
 

Detailed Description

template<class ThrustVector>
struct dg::View< ThrustVector >

A vector view class, usable in dg functions.

The view class holds a pointer and a size. It does not own the pointer. The user is responsible for allocating and deallocating memory. The intention is to use Views in dg::blas1 functions.

The class can be used as a traditional "view" in the sense that it can view part of a larger contiguous chunk of data and thus apply operations to only part of that data. The second use would be to imitate for example a full dg::DVec without allocating or copying memory for it. This might be useful if you want to use the dg::blas1 functions without specializing TensorTraits for your own vector class or deep copying data, like the following example demonstrates:

SomeDeviceVectorClass vector( 1e6, 20.); //vector of size 1e6, all elements equal 20
//create a view of a device vector to enable parallel execution
dg::View<dg::DVec> view( vector.data(), vector.size());
dg::blas1::copy( 7., view); //elements of vector now equal 7 instead of 20
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
A vector view class, usable in dg functions.
Definition: view.h:43
Attention
when constructing a View from a pointer the user also promises that the pointer can be dereferenced on the device the View acts on.
Note
cannot be used in dg::construct or dg::assign
You cannot have a View of an MPI_Vector but you can have an MPI_Vector of View
Template Parameters
ThrustVectorTensorTraits exists for this class and the tensor_category derives from ThrustVectorTag

Member Typedef Documentation

◆ const_iterator

template<class ThrustVector >
using dg::View< ThrustVector >::const_iterator = typename ThrustVector::const_iterator

◆ const_pointer

template<class ThrustVector >
using dg::View< ThrustVector >::const_pointer = typename ThrustVector::const_pointer

◆ iterator

template<class ThrustVector >
using dg::View< ThrustVector >::iterator = std::conditional_t<std::is_const<ThrustVector>::value, typename ThrustVector::const_iterator, typename ThrustVector::iterator>

◆ pointer

template<class ThrustVector >
using dg::View< ThrustVector >::pointer = std::conditional_t<std::is_const<ThrustVector>::value, typename ThrustVector::const_pointer, typename ThrustVector::pointer>

Constructor & Destructor Documentation

◆ View() [1/3]

template<class ThrustVector >
dg::View< ThrustVector >::View ( void  )
inline

Initialize empty view.

◆ View() [2/3]

template<class ThrustVector >
template<class OtherView >
dg::View< ThrustVector >::View ( OtherView< ThrustVector > &  src)
inline

Construct from another View or Vector.

The pointer types must be compatible

Template Parameters
OtherViewMust provide members: data() and size()
Parameters
srcInitialize from src.data() and src.size()

◆ View() [3/3]

template<class ThrustVector >
template<class InputIterator >
dg::View< ThrustVector >::View ( InputIterator  data,
unsigned  size 
)
inline

Construct view from pointer and size.

Parameters
datathe beginning of the contiguous chunk of data
sizethe number of elements in the contiguous chunk of data
Template Parameters
InputIteratorpointer must be constructible from this type
Attention
when constructing a View from a pointer the user also promises that the pointer can be dereferenced on the device the View acts on.

Member Function Documentation

◆ begin()

template<class ThrustVector >
iterator dg::View< ThrustVector >::begin ( ) const
inline

Iterator to the beginning.

Returns
iterator to the first element

◆ cbegin()

template<class ThrustVector >
const_iterator dg::View< ThrustVector >::cbegin ( ) const
inline

const Iterator to the beginning

Returns
iterator to the first element

◆ cend()

template<class ThrustVector >
const_iterator dg::View< ThrustVector >::cend ( ) const
inline

const Iterator to the end

Returns
iterator to the end

◆ construct()

template<class ThrustVector >
template<class InputIterator >
void dg::View< ThrustVector >::construct ( InputIterator  data,
unsigned  size 
)
inline

Construct view from pointer and size.

Parameters
datathe beginning of the contiguous chunk of data
sizethe number of elements in the contiguous chunk of data
Template Parameters
InputIteratorpointer must be constructible from this type
Attention
when constructing a View from a pointer the user also promises that the pointer can be dereferenced on the device the View acts on.

◆ data()

template<class ThrustVector >
pointer dg::View< ThrustVector >::data ( ) const
inline

Constant Reference of the pointer.

Returns
pointer to first element

◆ end()

template<class ThrustVector >
iterator dg::View< ThrustVector >::end ( ) const
inline

Iterator to the end.

Returns
iterator to the end

◆ size()

template<class ThrustVector >
unsigned dg::View< ThrustVector >::size ( ) const
inline

Get the size.

Returns
number elements in the data view

◆ swap()

template<class ThrustVector >
void dg::View< ThrustVector >::swap ( View< ThrustVector > &  src)
inline

Swap pointer and size with another View.

Parameters
srcthe source view

The documentation for this struct was generated from the following file: