HILA
Loading...
Searching...
No Matches
ReductionVector< T > Class Template Reference

#include <reductionvector.h>

Public Member Functions

ReductionVectorallreduce (bool b=true)
 allreduce(bool) turns allreduce on or off. By default on.
 
T * data ()
 data() returns ptr to the raw storage
 
ReductionVectordelayed (bool b=true)
 deferred(bool) turns deferred on or off. By default turns on.
 
void init_product ()
 Init is to be called before every site loop.
 
void init_sum ()
 Init is to be called before every site loop.
 
ReductionVectornonblocking (bool b=true)
 nonblocking(bool) turns allreduce on or off. By default on.
 
template<typename S , std::enable_if_t< std::is_assignable< T &, S >::value, int > = 0>
void operator= (const S &rhs)
 
void operator= (std::nullptr_t np)
 Assignment from 0.
 
T & operator[] (const int i)
 And access operators - these do in practice everything already!
 
void reduce ()
 Complete non-blocking or delayed reduction.
 
void reduce_product ()
 
void reduce_sum ()
 
 ReductionVector ()=default
 
size_t size () const
 methods from std::vector:
 
void start_reduce ()
 For delayed reduction, reduce starts or completes the reduction operation.
 
void wait ()
 Wait for MPI to complete, if it is currently going on.
 
 ~ReductionVector ()
 Destructor cleans up communications if they are in progress.
 

Detailed Description

template<typename T>
class ReductionVector< T >

Special reduction class for arrays: declare a reduction array as ReductionVector<T> a(size);

This can be used within site loops as onsites(ALL ) { int i = ... a[i] += ... }

or outside site loops as usual. Reductions: += *= sum or product reduction NOTE: size of the reduction vector must be same on all nodes! By default reduction is "allreduce", i.e. all nodes get the same result.

Reduction can be customized by using methods: a.size() : return the size of the array a.resize(new_size) : change size of array (all nodes must use same size!) a[i] : get/set element i

a.allreduce(bool) : turn allreduce on/off (default=true) a.nonblocking(bool) : turn non-blocking reduction on/off a.delayed(bool) : turn delayed reduction on/off

a.wait() : for non-blocking reduction, wait() has to be called after the loop to complete the reduction a.reduce() : for delayed reduction starts/completes the reduction

a.is_allreduce() : queries the reduction status is_nonblocking() is_delayed()

a.push_back(element) : add one element to The same reduction variable can be used again

Definition at line 44 of file reductionvector.h.

Constructor & Destructor Documentation

◆ ReductionVector()

template<typename T >
ReductionVector< T >::ReductionVector ( )
explicitdefault

Initialize to zero by default (? exception to other variables) allreduce = true by default

Member Function Documentation

◆ operator=()

template<typename T >
template<typename S , std::enable_if_t< std::is_assignable< T &, S >::value, int > = 0>
void ReductionVector< T >::operator= ( const S &  rhs)
inline

Assignment is used only outside site loops - wait for comms if needed Make this return void, hard to imagine it is used for anything useful

Definition at line 184 of file reductionvector.h.

◆ reduce_product()

template<typename T >
void ReductionVector< T >::reduce_product ( )
inline

Product reduction – currently works only for scalar data types. For Complex, Matrix and Vector data product is not element-wise. TODO: Array or std::array ? TODO: implement using custom MPI ops (if needed)

Definition at line 233 of file reductionvector.h.

◆ reduce_sum()

template<typename T >
void ReductionVector< T >::reduce_sum ( )
inline

Start sum reduction – works only if the type T addition == element-wise addition. This is true for all hila predefined data types

Definition at line 217 of file reductionvector.h.


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