Template Numerical Library version\ main:c173bea
Loading...
Searching...
No Matches
TNL::Containers::DistributedNDArrayView< NDArrayView > Class Template Reference

Distributed N-dimensional array view. More...

#include <TNL/Containers/DistributedNDArrayView.h>

Collaboration diagram for TNL::Containers::DistributedNDArrayView< NDArrayView >:

Public Types

using ConstLocalViewType = typename NDArrayView::ConstViewType
 Compatible constant NDArrayView of the local array.
 
using ConstViewType = DistributedNDArrayView< typename NDArrayView::ConstViewType >
 Compatible constant DistributedNDArrayView type.
 
using DeviceType = typename NDArrayView::DeviceType
 Type of the device used for running operations on the array.
 
using IndexType = typename NDArrayView::IndexType
 Type of indices used for addressing the array elements.
 
using LocalBeginsType = LocalBeginsHolder< typename NDArrayView::SizesHolderType >
 Type which represents the position of the first local element in the global N-dimensional array. It has all static sizes set to 0.
 
using LocalRangeType = Subrange< IndexType >
 Type which represents an integer range [a, b).
 
using LocalViewType = NDArrayView
 Compatible NDArrayView of the local array.
 
using OverlapsType = typename NDArrayView::OverlapsType
 Sequence of integers representing the overlaps in each dimension of a distributed N-dimensional array.
 
using PermutationType = typename NDArrayView::PermutationType
 Permutation that is applied to indices when accessing the array elements.
 
using SizesHolderType = typename NDArrayView::SizesHolderType
 Type of the underlying object which represents the sizes of the N-dimensional array.
 
using ValueType = typename NDArrayView::ValueType
 Type of the values stored in the array.
 
using ViewType = DistributedNDArrayView< NDArrayView >
 Compatible DistributedNDArrayView type.
 

Public Member Functions

 DistributedNDArrayView ()=default
 Constructs an empty array view with zero size.
 
 DistributedNDArrayView (const DistributedNDArrayView &)=default
 A shallow-copy copy-constructor.
 
 DistributedNDArrayView (DistributedNDArrayView &&) noexcept=default
 Move constructor for initialization from rvalues.
 
 DistributedNDArrayView (NDArrayView localView, SizesHolderType globalSizes, LocalBeginsType localBegins, SizesHolderType localEnds, MPI::Comm communicator)
 Constructs an array view initialized by local array view, global sizes, local begins and ends, and MPI communicator.
 
void bind (DistributedNDArrayView view)
 Re-binds (re-initializes) the array view to a different view.
 
void bind (ValueType *data)
 Re-binds (re-initializes) the array view to the given raw pointer and preserves the current indexer.
 
void bind (ValueType *data, typename LocalViewType::IndexerType indexer)
 Re-binds (re-initializes) the array view to the given raw pointer and changes the indexer.
 
template<typename Device2 = DeviceType, typename Func >
void forAll (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements of the array.
 
template<typename Device2 = DeviceType, typename SkipBegins , typename SkipEnds , typename Func >
void forBoundary (const SkipBegins &skipBegins, const SkipEnds &skipEnds, Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements outside the given [skipBegins, skipEnds) range specified by global indices.
 
template<typename Device2 = DeviceType, typename Func >
void forBoundary (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all boundary elements of the array.
 
template<typename Device2 = DeviceType, typename Func >
void forGhosts (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements in the ghost region.
 
template<typename Device2 = DeviceType, typename Begins , typename Ends , typename Func >
void forInterior (const Begins &begins, const Ends &ends, Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements inside the given [begins, ends) range specified by global indices.
 
template<typename Device2 = DeviceType, typename Func >
void forInterior (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all internal elements of the array.
 
template<typename Device2 = DeviceType, typename Func >
void forLocalBoundary (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all local-boundary elements of the array.
 
template<typename Device2 = DeviceType, typename Func >
void forLocalInterior (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all local-internal elements of the array.
 
const MPI::CommgetCommunicator () const
 Returns the MPI communicator associated with the array.
 
ConstLocalViewType getConstLocalView () const
 Returns a non-modifiable view of the local array.
 
ConstViewType getConstView () const
 Returns a non-modifiable view of the array.
 
ValueTypegetData ()
 Returns a raw pointer to the local data.
 
std::add_const_t< ValueType > * getData () const
 Returns a const-qualified raw pointer to the local data.
 
LocalBeginsType getLocalBegins () const
 Returns the beginning position of the local array in the global N-dimensional array.
 
SizesHolderType getLocalEnds () const
 Returns the ending position of the local array in the global N-dimensional array.
 
template<std::size_t level>
LocalRangeType getLocalRange () const
 Returns a specific [begin, end) subrange of the local array in the global N-dimensional array.
 
IndexType getLocalStorageSize () const
 Returns the size (number of elements) needed to store the local N-dimensional array.
 
LocalViewType getLocalView ()
 Returns a modifiable view of the local array.
 
template<std::size_t level>
__cuda_callable__ IndexType getOverlap () const
 Returns the overlap of a distributed N-dimensional array along the specified axis.
 
__cuda_callable__ OverlapsTypegetOverlaps ()
 Returns the N-dimensional overlaps holder instance.
 
__cuda_callable__ const OverlapsTypegetOverlaps () const
 Returns the N-dimensional overlaps holder instance.
 
template<std::size_t level>
IndexType getSize () const
 Returns a specific component of the N-dimensional global sizes.
 
const SizesHolderTypegetSizes () const
 Returns the N-dimensional sizes of the global array.
 
template<typename... IndexTypes>
IndexType getStorageIndex (IndexTypes &&... indices) const
 Returns the local storage index for given global indices.
 
ViewType getView ()
 Returns a modifiable view of the array.
 
bool operator!= (const DistributedNDArrayView &other) const
 Compares the array with another distributed N-dimensional array.
 
template<typename... IndexTypes>
ValueTypeoperator() (IndexTypes &&... indices)
 Accesses an element of the array.
 
template<typename... IndexTypes>
const ValueTypeoperator() (IndexTypes &&... indices) const
 Accesses an element of the array.
 
DistributedNDArrayViewoperator= (const DistributedNDArrayView &other)=default
 Copy-assignment operator for deep-copying data from another array.
 
template<typename OtherArray >
DistributedNDArrayViewoperator= (const OtherArray &other)
 Templated copy-assignment operator for deep-copying data from another array.
 
bool operator== (const DistributedNDArrayView &other) const
 Compares the array with another distributed N-dimensional array.
 
ValueTypeoperator[] (IndexType index)
 Accesses an element in a one-dimensional array.
 
const ValueTypeoperator[] (IndexType index) const
 Accesses an element in a one-dimensional array.
 
void reset ()
 Resets the array view to the empty state.
 

Static Public Member Functions

static constexpr std::size_t getDimension ()
 Returns the dimension of the N-dimensional array, i.e. N.
 

Protected Attributes

MPI::Comm communicator = MPI_COMM_NULL
 MPI communicator associated with the array.
 
SizesHolderType globalSizes
 Global sizes of the whole distributed N-dimensional array.
 
LocalBeginsType localBegins
 Global indices of the first local element in the whole N-dimensional array.
 
SizesHolderType localEnds
 Global indices of the end-of-range element, [localBegins, localEnds).
 
NDArrayView localView
 View of the N-dimensional array containing the local elements and overlaps.
 

Detailed Description

template<typename NDArrayView>
class TNL::Containers::DistributedNDArrayView< NDArrayView >

Distributed N-dimensional array view.

Template Parameters
NDArrayViewType of the N-dimensional array view which is used to access the local elements. It must be an instance of the NDArrayView template.

Member Function Documentation

◆ forAll()

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forAll ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements of the array.

Each MPI rank iterates over all of its local elements.

See NDArrayView::forAll for the requirements on the function f.

◆ forBoundary() [1/2]

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename SkipBegins , typename SkipEnds , typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forBoundary ( const SkipBegins & skipBegins,
const SkipEnds & skipEnds,
Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements outside the given [skipBegins, skipEnds) range specified by global indices.

Each MPI rank iterates over its local elements outside the range.

See NDArrayView::forAll for the requirements on the function f.

◆ forBoundary() [2/2]

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forBoundary ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all boundary elements of the array.

Each MPI rank iterates over its local elements which are neighbours of global boundaries.

See NDArrayView::forAll for the requirements on the function f.

◆ forGhosts()

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forGhosts ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements in the ghost region.

Each MPI rank iterates over elements which are in the overlapping region (i.e., owned by a different MPI rank). If all overlaps are 0, it has no effect.

See NDArrayView::forAll for the requirements on the function f.

◆ forInterior() [1/2]

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Begins , typename Ends , typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forInterior ( const Begins & begins,
const Ends & ends,
Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements inside the given [begins, ends) range specified by global indices.

Each MPI rank iterates over its local elements from the range.

See NDArrayView::forAll for the requirements on the function f.

◆ forInterior() [2/2]

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forInterior ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all internal elements of the array.

Each MPI rank iterates over its local elements which are not neighbours of global boundaries.

See NDArrayView::forAll for the requirements on the function f.

◆ forLocalBoundary()

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forLocalBoundary ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all local-boundary elements of the array.

Each MPI rank iterates over its local elements which are neighbours of overlaps. If all overlaps are 0, it has no effect.

See NDArrayView::forAll for the requirements on the function f.

◆ forLocalInterior()

template<typename NDArrayView >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::DistributedNDArrayView< NDArrayView >::forLocalInterior ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all local-internal elements of the array.

Each MPI rank iterates over its local elements which are not neighbours of overlaps. If all overlaps are 0, it is equivalent to forAll.

See NDArrayView::forAll for the requirements on the function f.

◆ getLocalRange()

template<typename NDArrayView >
template<std::size_t level>
LocalRangeType TNL::Containers::DistributedNDArrayView< NDArrayView >::getLocalRange ( ) const
inlinenodiscard

Returns a specific [begin, end) subrange of the local array in the global N-dimensional array.

Template Parameters
levelInteger specifying the component of the sizes to be returned.

◆ getOverlap()

template<typename NDArrayView >
template<std::size_t level>
__cuda_callable__ IndexType TNL::Containers::DistributedNDArrayView< NDArrayView >::getOverlap ( ) const
inlinenodiscard

Returns the overlap of a distributed N-dimensional array along the specified axis.

Template Parameters
levelInteger specifying the axis of the array.

◆ getSize()

template<typename NDArrayView >
template<std::size_t level>
IndexType TNL::Containers::DistributedNDArrayView< NDArrayView >::getSize ( ) const
inlinenodiscard

Returns a specific component of the N-dimensional global sizes.

Template Parameters
levelInteger specifying the component of the sizes to be returned.

◆ getStorageIndex()

template<typename NDArrayView >
template<typename... IndexTypes>
IndexType TNL::Containers::DistributedNDArrayView< NDArrayView >::getStorageIndex ( IndexTypes &&... indices) const
inlinenodiscard

Returns the local storage index for given global indices.

Parameters
indicesGlobal indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().
Returns
An index that can be used to address the element in a local one-dimensional array.

◆ operator()() [1/2]

template<typename NDArrayView >
template<typename... IndexTypes>
ValueType & TNL::Containers::DistributedNDArrayView< NDArrayView >::operator() ( IndexTypes &&... indices)
inlinenodiscard

Accesses an element of the array.

Only local elements or elements in the overlapping region can be accessed.

Parameters
indicesGlobal indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().
Returns
Reference to the array element.

◆ operator()() [2/2]

template<typename NDArrayView >
template<typename... IndexTypes>
const ValueType & TNL::Containers::DistributedNDArrayView< NDArrayView >::operator() ( IndexTypes &&... indices) const
inlinenodiscard

Accesses an element of the array.

Only local elements or elements in the overlapping region can be accessed.

Parameters
indicesGlobal indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().
Returns
Constant reference to the array element.

◆ operator=()

Copy-assignment operator for deep-copying data from another array.

This is just like the operator on a regular array, but the sizes must match (i.e. copy-assignment cannot resize).

Note that there is no move-assignment operator, so expressions like a = b.getView() are resolved as copy-assignment.

◆ operator[]() [1/2]

template<typename NDArrayView >
ValueType & TNL::Containers::DistributedNDArrayView< NDArrayView >::operator[] ( IndexType index)
inlinenodiscard

Accesses an element in a one-dimensional array.

Only local elements or elements in the overlapping region can be accessed.

Warning
This function can be used only when the dimension of the array is equal to 1.
Parameters
indexGlobal index of the element in the one-dimensional array.
Returns
Reference to the array element.

◆ operator[]() [2/2]

template<typename NDArrayView >
const ValueType & TNL::Containers::DistributedNDArrayView< NDArrayView >::operator[] ( IndexType index) const
inlinenodiscard

Accesses an element in a one-dimensional array.

Only local elements or elements in the overlapping region can be accessed.

Warning
This function can be used only when the dimension of the array is equal to 1.
Parameters
indexGlobal index of the element in the one-dimensional array.
Returns
Reference to the array element.

Member Data Documentation

◆ localBegins

template<typename NDArrayView >
LocalBeginsType TNL::Containers::DistributedNDArrayView< NDArrayView >::localBegins
protected

Global indices of the first local element in the whole N-dimensional array.

Note that localBegins and localEnds have different static sizes (and hence different C++ type): localBegins is always 0, localEnds has always the full static size.


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