|
| DistributedVector (const DistributedVector &)=default |
| Copy constructor (makes a deep copy).
|
| DistributedVector (const DistributedVector &vector, const AllocatorType &allocator) |
| Copy constructor with a specific allocator (makes a deep copy).
|
| DistributedVector (DistributedVector &&) noexcept=default |
| Default move constructor.
|
| DistributedArray ()=default |
| Constructs an empty array with zero size.
|
| DistributedArray (const AllocatorType &allocator) |
| Constructs an empty array and sets the provided allocator.
|
| DistributedArray (const DistributedArray &array) |
| Copy constructor (makes a deep copy).
|
| DistributedArray (const DistributedArray &array, const AllocatorType &allocator) |
| Copy constructor with a specific allocator (makes a deep copy).
|
| DistributedArray (DistributedArray &&) noexcept=default |
| DistributedArray (LocalRangeType localRange, Index ghosts, Index globalSize, const MPI::Comm &communicator, const AllocatorType &allocator=AllocatorType()) |
ConstLocalViewType | getConstLocalView () const |
| Returns a non-modifiable view of the local part of the vector.
|
ConstLocalViewType | getConstLocalViewWithGhosts () const |
| Returns a non-modifiable view of the local part of the vector, including ghost values.
|
ConstViewType | getConstView () const |
| Returns a non-modifiable view of the vector.
|
LocalViewType | getLocalView () |
| Returns a modifiable view of the local part of the vector.
|
LocalViewType | getLocalViewWithGhosts () |
| Returns a modifiable view of the local part of the vector, including ghost values.
|
ViewType | getView () |
| Returns a modifiable view of the vector.
|
| operator ConstViewType () const |
| Conversion operator to a non-modifiable view of the vector.
|
| operator ViewType () |
| Conversion operator to a modifiable view of the vector.
|
template<typename Vector, typename..., typename = std::enable_if_t< HasSubscriptOperator< Vector >::value >> |
DistributedVector & | operator%= (const Vector &vector) |
template<typename Vector, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator%= (const Vector &vector) |
template<typename Scalar, typename..., typename = std::enable_if_t< ! HasSubscriptOperator< Scalar >::value >> |
DistributedVector & | operator%= (Scalar c) |
template<typename Scalar, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator%= (Scalar c) |
template<typename Vector, typename..., typename = std::enable_if_t< HasSubscriptOperator< Vector >::value >> |
DistributedVector & | operator*= (const Vector &vector) |
template<typename Vector, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator*= (const Vector &vector) |
template<typename Scalar, typename..., typename = std::enable_if_t< ! HasSubscriptOperator< Scalar >::value >> |
DistributedVector & | operator*= (Scalar c) |
template<typename Scalar, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator*= (Scalar c) |
template<typename Vector, typename..., typename = std::enable_if_t< HasSubscriptOperator< Vector >::value >> |
DistributedVector & | operator+= (const Vector &vector) |
template<typename Vector, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator+= (const Vector &vector) |
template<typename Scalar, typename..., typename = std::enable_if_t< ! HasSubscriptOperator< Scalar >::value >> |
DistributedVector & | operator+= (Scalar c) |
template<typename Scalar, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator+= (Scalar c) |
template<typename Vector, typename..., typename = std::enable_if_t< HasSubscriptOperator< Vector >::value >> |
DistributedVector & | operator-= (const Vector &vector) |
template<typename Vector, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator-= (const Vector &vector) |
template<typename Scalar, typename..., typename = std::enable_if_t< ! HasSubscriptOperator< Scalar >::value >> |
DistributedVector & | operator-= (Scalar c) |
template<typename Scalar, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator-= (Scalar c) |
template<typename Vector, typename..., typename = std::enable_if_t< HasSubscriptOperator< Vector >::value >> |
DistributedVector & | operator/= (const Vector &vector) |
template<typename Vector, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator/= (const Vector &vector) |
template<typename Scalar, typename..., typename = std::enable_if_t< ! HasSubscriptOperator< Scalar >::value >> |
DistributedVector & | operator/= (Scalar c) |
template<typename Scalar, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator/= (Scalar c) |
DistributedVector & | operator= (const DistributedVector &)=default |
| Copy-assignment operator for copying data from another vector.
|
template<typename Vector, typename..., typename = std::enable_if_t< HasSubscriptOperator< Vector >::value >> |
DistributedVector & | operator= (const Vector &vector) |
template<typename Vector, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator= (const Vector &vector) |
DistributedVector & | operator= (DistributedVector &&) noexcept(false)=default |
| Move-assignment operator for acquiring data from rvalues.
|
template<typename Scalar, typename..., typename = std::enable_if_t< ! HasSubscriptOperator< Scalar >::value >> |
DistributedVector & | operator= (Scalar c) |
template<typename Scalar, typename..., typename> |
DistributedVector< Real, Device, Index, Allocator > & | operator= (Scalar c) |
| DistributedArray ()=default |
| Constructs an empty array with zero size.
|
void | copyFromGlobal (ConstLocalViewType globalArray) |
bool | empty () const |
void | forElements (IndexType begin, IndexType end, Function &&f) |
| Process the lambda function f for each array element in interval [ begin, end).
|
AllocatorType | getAllocator () const |
| Returns the allocator associated to the array.
|
const MPI::Comm & | getCommunicator () const |
| Returns the MPI communicator associated to the array.
|
ConstLocalViewType | getConstLocalView () const |
| Returns a non-modifiable view of the local part of the array.
|
ConstLocalViewType | getConstLocalViewWithGhosts () const |
| Returns a non-modifiable view of the local part of the array, including ghost values.
|
ConstViewType | getConstView () const |
| Returns a non-modifiable view of the array.
|
ValueType | getElement (IndexType i) const |
IndexType | getGhosts () const |
const LocalRangeType & | getLocalRange () const |
| Returns the local range of the distributed array.
|
LocalViewType | getLocalView () |
| Returns a modifiable view of the local part of the array.
|
LocalViewType | getLocalViewWithGhosts () |
| Returns a modifiable view of the local part of the array, including ghost values.
|
IndexType | getSize () const |
std::shared_ptr< SynchronizerType > | getSynchronizer () const |
int | getValuesPerElement () const |
ViewType | getView () |
| Returns a modifiable view of the array.
|
void | loadFromGlobalFile (const String &fileName, bool allowCasting=false) |
| operator ConstViewType () const |
| Conversion operator to a non-modifiable view of the array.
|
| operator ViewType () |
| Conversion operator to a modifiable view of the array.
|
bool | operator!= (const Array &array) const |
DistributedArray< Real, Devices::Host, int, Allocator > & | operator= (const Array &array) |
bool | operator== (const Array &array) const |
__cuda_callable__ ValueType & | operator[] (IndexType i) |
void | reset () |
void | setDistribution (LocalRangeType localRange, int ghosts, int globalSize, const MPI::Comm &communicator) |
| Set new global size and distribution of the array.
|
void | setElement (IndexType i, ValueType value) |
void | setLike (const Array &array) |
void | setSynchronizer (std::shared_ptr< SynchronizerType > synchronizer, int valuesPerElement=1) |
void | setValue (ValueType value) |
void | startSynchronization () |
void | waitForSynchronization () const |
template<typename
Real, typename Device = Devices::Host, typename Index = int, typename Allocator = typename Allocators::Default< Device >::template Allocator< Real >>
class TNL::Containers::DistributedVector< Real, Device, Index, Allocator >
DistributedVector extends DistributedArray with algebraic operations.
- Example
#include <iostream>
#include <TNL/Containers/BlockPartitioning.h>
#include <TNL/Containers/DistributedVector.h>
#include <TNL/MPI/ScopedInitializer.h>
template< typename Device >
void
distributedVectorExample()
{
using IndexType = typename VectorType::IndexType;
using LocalRangeType = typename VectorType::LocalRangeType;
const int size = 97;
const int ghosts = ( communicator.
size() > 1 ) ? 4 : 0;
VectorType v( localRange, ghosts, size, communicator );
v.forElements( 0,
size,
{
value = idx;
} );
const int sum = TNL::sum( v );
if( communicator.
rank() == 0 )
}
int
main( int argc, char* argv[] )
{
if( TNL::MPI::GetRank() == 0 )
distributedVectorExample< TNL::Devices::Host >();
#ifdef __CUDACC__
TNL::MPI::Barrier();
if( TNL::MPI::GetRank() == 0 )
distributedVectorExample< TNL::Devices::Cuda >();
#endif
}
#define __cuda_callable__
Definition Macros.h:49
DistributedVector extends DistributedArray with algebraic operations.
Definition DistributedVector.h:24
An RAII wrapper for custom MPI communicators.
Definition Comm.h:63
int size() const
Returns the size of the group associated with a communicator.
Definition Comm.h:227
int rank() const
Determines the rank of the calling process in the communicator.
Definition Comm.h:220
Subrange< Index > splitRange(Index rangeBegin, Index rangeEnd, int rank, int num_subintervals)
A helper function which splits a one-dimensional range.
Definition BlockPartitioning.h:27
Definition ScopedInitializer.h:63
- Output
Rank 2: rank on node is 2, using GPU id 0 of 2
Environment:
CUDA_VISIBLE_DEVICES=
Rank 0: rank on node is 0, using GPU id 0 of 2
Environment:
CUDA_VISIBLE_DEVICES=
Rank 1: rank on node is 1, using GPU id 1 of 2
Environment:
CUDA_VISIBLE_DEVICES=
Rank 3: rank on node is 3, using GPU id 1 of 2
Environment:
CUDA_VISIBLE_DEVICES=
Rank 1 has subrange TNL::Containers::Subrange<int>( 25, 49 )
Rank 3 has subrange TNL::Containers::Subrange<int>( 73, 97 )
Rank 2 has subrange TNL::Containers::Subrange<int>( 49, 73 )
The first test runs on CPU ...
Rank 0 has subrange TNL::Containers::Subrange<int>( 0, 25 )
Global sum is 4656
The second test runs on GPU ...
Rank 1 has subrange TNL::Containers::Subrange<int>( 25, 49 )
Rank 0 has subrange TNL::Containers::Subrange<int>( 0, 25 )
Rank 3 has subrange TNL::Containers::Subrange<int>( 73, 97 )
Rank 2 has subrange TNL::Containers::Subrange<int>( 49, 73 )
Global sum is 4656