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 {
typedef ... result_type;
typedef ... argument_type;
ReductionOp();
ReductionOp(const ReductionOp&);
result_type operator()() const;
result_type operator()(const result_type&) const;
void operator()(result_type&, const result_type&) const;
void operator()(result_type&, const argument_type&) const;
};
For example, a vector sum function might look like:
struct VectorSum {
typedef double result_type;
typedef std::vector<double> argument_type;
result_type operator()() const { return 0; }
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];
}
};
- 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
-
| opT | The reduction operation type |
Definition at line 196 of file reduce_task.h.