TiledArray  0.7.0
TiledArray::detail::ReduceTask< opT > Class Template Reference

Reduce task. More...

#include <reduce_task.h>

Public Member Functions

 ReduceTask ()
 Default constructor. More...
 
 ReduceTask (World &world, const opT &op=opT(), madness::CallbackInterface *callback=nullptr)
 Constructor. More...
 
 ReduceTask (ReduceTask< opT > &&other) noexcept
 Move constructor. More...
 
 ~ReduceTask ()
 Destructor. More...
 
ReduceTask< opT > & operator= (ReduceTask< opT > &&other) noexcept
 Move assignment operator. More...
 
 ReduceTask (const ReduceTask< opT > &)=delete
 
ReduceTask< opT > & operator= (const ReduceTask< opT > &)=delete
 
template<typename Arg >
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...
 

Detailed Description

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

Reduce task.

This task will reduce an arbitrary number of objects. It 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 ... 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
result_type operator()(const result_type&) const;
// Reduce two result objects
void operator()(result_type&, const result_type&) const;
// Reduce an argument
void operator()(result_type&, const argument_type&) const;
}; // struct ReductionOp

For example, a vector sum function might look like:

struct VectorSum {
// typedefs
typedef double result_type;
typedef std::vector<double> argument_type;
// Compiler generated constructors and assignment operators are 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 argument_type& arg) const {
for(std::size_t i = 0ul; i < first.size(); ++i)
result += arg[i];
}
}; // struct VectorProduct
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 196 of file reduce_task.h.

Constructor & Destructor Documentation

◆ ReduceTask() [1/4]

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

Default constructor.

Definition at line 469 of file reduce_task.h.

◆ ReduceTask() [2/4]

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

Constructor.

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

Definition at line 478 of file reduce_task.h.

◆ ReduceTask() [3/4]

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

Move constructor.

Parameters
otherThe object to be moved

Definition at line 486 of file reduce_task.h.

◆ ~ReduceTask()

template<typename opT>
TiledArray::detail::ReduceTask< opT >::~ReduceTask ( )
inline

Destructor.

If the reduction has not been submitted or destroy() has not been called, it will be submitted when the destructor is called.

Definition at line 497 of file reduce_task.h.

◆ ReduceTask() [4/4]

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

Member Function Documentation

◆ add()

template<typename opT>
template<typename Arg >
int TiledArray::detail::ReduceTask< opT >::add ( const Arg &  arg,
madness::CallbackInterface *  callback = nullptr 
)
inline

Add an argument to the reduction task.

arg may be of the argument type of opT, a Future to the argument type, or RemoteReference<FutureImpl> to the argument type.

Template Parameters
ArgThe argument type
Parameters
argThe argument that will be reduced
callbackThe callback that will be invoked when this argument pair has been reduced [ default = nullptr ]

Definition at line 524 of file reduce_task.h.

Here is the caller graph for this function:

◆ count()

template<typename opT>
int TiledArray::detail::ReduceTask< opT >::count ( ) const
inline

Argument count.

Returns
The total number of arguments added to this task

Definition at line 534 of file reduce_task.h.

◆ operator bool()

template<typename opT>
TiledArray::detail::ReduceTask< opT >::operator bool ( ) const
inline

Type conversion operator.

Returns
true if the task object is initialized.

Definition at line 559 of file reduce_task.h.

◆ operator=() [1/2]

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

Move assignment operator.

Parameters
otherThe object to be moved

Definition at line 502 of file reduce_task.h.

Here is the caller graph for this function:

◆ operator=() [2/2]

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

◆ submit()

template<typename opT>
Future<result_type> TiledArray::detail::ReduceTask< opT >::submit ( )
inline

Submit the reduction task to the task queue.

Returns
The result of the reduction
Note
Arguments can no longer be added to the reduction after calling submit().

Definition at line 541 of file reduce_task.h.

Here is the caller graph for this function:

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