Template Numerical Library version\ main:4e58ea6
|
Distributed N-dimensional array. More...
#include <TNL/Containers/DistributedNDArray.h>
Public Types | |
using | AllocatorType = typename NDArray::AllocatorType |
Allocator type used for allocating the array. | |
using | ConstLocalViewType = typename NDArray::ConstViewType |
Compatible constant NDArrayView of the local array. | |
using | ConstViewType = DistributedNDArrayView< typename NDArray::ConstViewType > |
Compatible constant DistributedNDArrayView type. | |
using | DeviceType = typename NDArray::DeviceType |
Type of the device used for running operations on the array. | |
using | IndexType = typename NDArray::IndexType |
Type of indices used for addressing the array elements. | |
using | LocalBeginsType = LocalBeginsHolder< typename NDArray::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 = typename NDArray::ViewType |
Compatible NDArrayView of the local array. | |
using | OverlapsType = typename NDArray::OverlapsType |
Sequence of integers representing the overlaps in each dimension of a distributed N-dimensional array. | |
using | PermutationType = typename NDArray::PermutationType |
Permutation that is applied to indices when accessing the array elements. | |
using | SizesHolderType = typename NDArray::SizesHolderType |
Type of the underlying object which represents the sizes of the N-dimensional array. | |
using | ValueType = typename NDArray::ValueType |
Type of the values stored in the array. | |
using | ViewType = DistributedNDArrayView< typename NDArray::ViewType > |
Compatible DistributedNDArrayView type. | |
Public Member Functions | |
DistributedNDArray ()=default | |
Constructs an empty array with zero size. | |
DistributedNDArray (const AllocatorType &allocator) | |
Constructs an empty array and sets the provided allocator. | |
DistributedNDArray (const DistributedNDArray &)=default | |
Copy constructor (makes a deep copy). | |
DistributedNDArray (const DistributedNDArray &other, const AllocatorType &allocator) | |
Copy constructor with a specific allocator (makes a deep copy). | |
DistributedNDArray (DistributedNDArray &&) noexcept=default | |
Move constructor for initialization from rvalues. | |
void | allocate () |
Computes the distributed storage size and allocates the local array. | |
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. | |
AllocatorType | getAllocator () const |
Returns the allocator associated with the array. | |
const MPI::Comm & | getCommunicator () 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. | |
ValueType * | getData () |
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. | |
template<typename... IndexTypes> | |
ValueType | getElement (IndexTypes &&... indices) const |
A "safe" accessor for array elements. | |
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__ OverlapsType & | getOverlaps () |
Returns the N-dimensional overlaps holder instance. | |
__cuda_callable__ const OverlapsType & | getOverlaps () 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 SizesHolderType & | getSizes () 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 DistributedNDArray &other) const |
Compares the array with another distributed N-dimensional array. | |
template<typename... IndexTypes> | |
ValueType & | operator() (IndexTypes &&... indices) |
Accesses an element of the array. | |
template<typename... IndexTypes> | |
const ValueType & | operator() (IndexTypes &&... indices) const |
Accesses an element of the array. | |
DistributedNDArray & | operator= (const DistributedNDArray &other)=default |
Copy-assignment operator for deep-copying data from another array. Mismatched sizes cause reallocations. | |
template<typename OtherArray > | |
DistributedNDArray & | operator= (const OtherArray &other) |
Templated copy-assignment operator for deep-copying data from another array. | |
DistributedNDArray & | operator= (DistributedNDArray &&) noexcept(false)=default |
Move-assignment operator for acquiring data from rvalues. | |
bool | operator== (const DistributedNDArray &other) const |
Compares the array with another distributed N-dimensional array. | |
ValueType & | operator[] (IndexType index) |
Accesses an element in a one-dimensional array. | |
const ValueType & | operator[] (IndexType index) const |
Accesses an element in a one-dimensional array. | |
void | reset () |
Resets the array to the empty state. | |
template<std::size_t level> | |
void | setDistribution (IndexType begin, IndexType end, const MPI::Comm &communicator=MPI_COMM_WORLD) |
Sets the distribution of the arrray among MPI ranks along the given axis. | |
void | setLike (const DistributedNDArray &other) |
Sets sizes of the array to the sizes of an existing array. | |
template<typename... IndexTypes> | |
void | setSizes (IndexTypes &&... sizes) |
Sets the global sizes of the array, but does not allocate storage. | |
void | setValue (ValueType value) |
Sets all elements of the array to given value. | |
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. | |
NDArray | localArray |
The N-dimensional array which stores the local elements and overlaps. | |
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) . | |
Distributed N-dimensional array.
NDArray | Type of the N-dimensional array which is used to store the local elements. It can be NDArray or SlicedNDArray. |
|
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
.
|
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
.
|
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
.
|
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
.
|
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
.
|
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
.
|
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
.
|
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
.
|
inlinenodiscard |
A "safe" accessor for array elements.
It can be called only from the host code and it will do a slow copy from the device.
|
inlinenodiscard |
Returns a specific [begin, end)
subrange of the local array in the global N-dimensional array.
level | Integer specifying the component of the sizes to be returned. |
|
inlinenodiscard |
Returns the overlap of a distributed N-dimensional array along the specified axis.
level | Integer specifying the axis of the array. |
|
inlinenodiscard |
Returns a specific component of the N-dimensional global sizes.
level | Integer specifying the component of the sizes to be returned. |
|
inlinenodiscard |
Returns the local storage index for given global indices.
indices | Global indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension(). |
|
inlinenodiscard |
Accesses an element of the array.
Only local elements or elements in the overlapping region can be accessed.
indices | Global indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension(). |
|
inlinenodiscard |
Accesses an element of the array.
Only local elements or elements in the overlapping region can be accessed.
indices | Global indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension(). |
|
inlinenodiscard |
Accesses an element in a one-dimensional array.
Only local elements or elements in the overlapping region can be accessed.
index | Global index of the element in the one-dimensional array. |
|
inlinenodiscard |
Accesses an element in a one-dimensional array.
Only local elements or elements in the overlapping region can be accessed.
index | Global index of the element in the one-dimensional array. |
|
inline |
Resets the array to the empty state.
The current data will be deallocated, thus all pointers and views to the array elements will become invalid.
|
inline |
Sets the distribution of the arrray among MPI ranks along the given axis.
level | Integer specifying the axis of the array to be distributed. |
begin | Index of the first element owned by the calling MPI rank. |
end | Index of the first element not owned by the calling MPI rank. I.e., the calling rank owns the range [begin, end) . |
communicator | MPI communicator to associate with the array. |
|
inline |
Sets sizes of the array to the sizes of an existing array.
If the array size changes, the current data will be deallocated, thus all pointers and views to the array alements will become invalid.
|
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.