TiledArray::detail::ReducePairTask< opT > Class Template Reference
Inheritance diagram for TiledArray::detail::ReducePairTask< opT >:
Collaboration diagram for TiledArray::detail::ReducePairTask< opT >:

Documentation

template<typename opT>
class TiledArray::detail::ReducePairTask< opT >

Reduce pair task.

This task will reduce an arbitrary number of pairs of objects. This task is optimized for reduction of data that is the result of other tasks or remote data. Also, it is assumed that individual reduction operations require a substantial amount of work (i.e. your reduction operation should reduce a vector of data, not two numbers). The reduction arguments are reduced as they become ready, which results in non- deterministic reduction order. This is much faster than a simple binary tree reduction since the reduction tasks do not have to wait for specific pairs of data. Though data that is not stored in a future can be used, it may not be the best choice in that case.
The reduction operation must have the following form:

struct ReductionOp {
// typedefs
typedef ... result_type;
typedef ... first_argument_type;
typedef ... second_argument_type;
// Constructors
ReductionOp();
ReductionOp(const ReductionOp&);
ReductionOp& operator=(const ReductionOp&);
// Reduction functions
// Make an empty result object
result_type operator()() const;
// Post process the result
const result_type& operator()(const result_type&) const;
// Reduce two result objects
void operator()(result_type&, const result_type&) const;
// Reduce an argument pair
void operator()(result_type&, const first_argument_type&,
const second_argument_type&) const;
}; // struct ReductionOp

For example, a dot product function might look like:

struct DotProduct {
// typedefs
typedef double result_type;
typedef std::vector<double> first_argument_type;
tyepdef std::vector<double> second_argument_type;
// Compiler generated constructors or assignment operator OK here
// Reduction functions
// Make an empty result object
result_type operator()() const { return 0; }
// Post process the result (no operation, passthrough)
const result_type& operator()(const result_type& result) const {
return result;
}
void operator()(result_type& result, const result_type& arg) const {
result += arg;
}
void operator()(result_type& result,
const first_argument_type& first, const second_argument_type&
second) const
{
assert(first.size() == second.size());
for(std::size_t i = 0ul; i < first.size(); ++i)
result += first[i] * second[i];
}
}; // struct DotProduct
Note
There is no need to add this object to the MADNESS task queue. It will be handled internally by the object. Simply call submit() to add this task to the task queue.
Template Parameters
opTThe reduction operation type

Definition at line 910 of file reduce_task.h.

Public Member Functions

 ReducePairTask ()
 Default constructor. More...
 
 ReducePairTask (World &world, const opT &op=opT(), madness::CallbackInterface *callback=nullptr)
 Constructor. More...
 
 ReducePairTask (ReducePairTask< opT > &&other) noexcept
 Move constructor. More...
 
ReducePairTask< opT > & operator= (ReducePairTask< opT > &&other) noexcept
 Move assignment operator. More...
 
 ReducePairTask (const ReducePairTask< opT > &)=delete
 Non-copyable. More...
 
ReducePairTask< opT > operator= (const ReducePairTask< opT > &)=delete
 
template<typename L , typename R >
void add (const L &left, const R &right, madness::CallbackInterface *callback=nullptr)
 Add a pair of arguments to the reduction task. More...
 
- Public Member Functions inherited from TiledArray::detail::ReduceTask< ReducePairOpWrapper< opT > >
 ReduceTask ()
 Default constructor. More...
 
 ReduceTask (World &world, const ReducePairOpWrapper< opT > &op=ReducePairOpWrapper< opT >(), madness::CallbackInterface *callback=nullptr)
 Constructor. More...
 
 ReduceTask (ReduceTask< ReducePairOpWrapper< opT > > &&other) noexcept
 Move constructor. More...
 
 ReduceTask (const ReduceTask< ReducePairOpWrapper< opT > > &)=delete
 
 ~ReduceTask ()
 Destructor. More...
 
ReduceTask< ReducePairOpWrapper< opT > > & operator= (ReduceTask< ReducePairOpWrapper< opT > > &&other) noexcept
 Move assignment operator. More...
 
ReduceTask< ReducePairOpWrapper< opT > > & operator= (const ReduceTask< ReducePairOpWrapper< opT > > &)=delete
 
int add (const Arg &arg, madness::CallbackInterface *callback=nullptr)
 Add an argument to the reduction task. More...
 
int count () const
 Argument count. More...
 
Future< result_type > submit ()
 Submit the reduction task to the task queue. More...
 
 operator bool () const
 Type conversion operator. More...
 

Constructor & Destructor Documentation

◆ ReducePairTask() [1/4]

template<typename opT >
TiledArray::detail::ReducePairTask< opT >::ReducePairTask ( )
inline

Default constructor.

Definition at line 923 of file reduce_task.h.

◆ ReducePairTask() [2/4]

template<typename opT >
TiledArray::detail::ReducePairTask< opT >::ReducePairTask ( World &  world,
const opT &  op = opT(),
madness::CallbackInterface *  callback = nullptr 
)
inline

Constructor.

Parameters
worldThe world that owns this task
opThe pair reduction operation [ default = opT() ]
callbackThe callback that will be invoked when this task is complete

Definition at line 931 of file reduce_task.h.

◆ ReducePairTask() [3/4]

template<typename opT >
TiledArray::detail::ReducePairTask< opT >::ReducePairTask ( ReducePairTask< opT > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherThe object to be moved

Definition at line 938 of file reduce_task.h.

◆ ReducePairTask() [4/4]

template<typename opT >
TiledArray::detail::ReducePairTask< opT >::ReducePairTask ( const ReducePairTask< opT > &  )
delete

Non-copyable.

Member Function Documentation

◆ add()

template<typename opT >
template<typename L , typename R >
void TiledArray::detail::ReducePairTask< opT >::add ( const L &  left,
const R &  right,
madness::CallbackInterface *  callback = nullptr 
)
inline

Add a pair of arguments to the reduction task.

left and right may be of the argument types of opT, a Future to the argument types, RemoteReference<FutureImpl> to the argument types, or any combination of the above.

Template Parameters
LThe left-hand object type
RThe right-hand object type
Parameters
leftThe left-hand argument that will be reduced
rightThe right-hand argument that will be reduced
callbackThe callback that will be invoked when this argument pair has been reduced [ default = nullptr ]

Definition at line 966 of file reduce_task.h.

Here is the caller graph for this function:

◆ operator=() [1/2]

template<typename opT >
ReducePairTask<opT> TiledArray::detail::ReducePairTask< opT >::operator= ( const ReducePairTask< opT > &  )
delete

◆ operator=() [2/2]

template<typename opT >
ReducePairTask<opT>& TiledArray::detail::ReducePairTask< opT >::operator= ( ReducePairTask< opT > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe object to be moved

Definition at line 944 of file reduce_task.h.


The documentation for this class was generated from the following file:
ReducePairTask< opT > & operator=(ReducePairTask< opT > &&other) noexcept
Move assignment operator.
Definition: reduce_task.h:944