template<typename T, typename TResult = T>
class bdm::experimental::GenericReducer< T, TResult >
Generic implementation of a reduction.
Provides the functions to iterates over all agents executing the agent_function_
and updating a thread-local and therefore partial result. The reduce_partial_results_
attribute specifies how these partial results should be combined into a single value. Let's assume we want to sum up the data
attribute of all agents.
auto sum_data = [](Agent* agent, uint64_t* tl_result) {
*tl_result += bdm_static_cast<TestAgent*>(agent)->GetData();
};
auto combine_tl_results = [](const SharedData<uint64_t>& tl_results) {
uint64_t result = 0;
for (auto& el : tl_results) {
result += el;
}
return result;
};
GenericReducer<uint64_t> reducer(sum_data, combine_tl_results);
rm->ForEachAgentParallel(reducer);
auto result = reducer.GetResult();
The optional argument filter
allows to reduce only a subset of all agents. The benefit in comparison with bdm::experimental::Reduce
is that multiple counters can be combined and processed in one sweep over all agents.
- See also
- bdm::experimental::Reducer`
Definition at line 76 of file reduce.h.