BioDynaMo  v1.05.120-25dc9790
Public Member Functions | Private Attributes | List of all members
bdm::experimental::GenericReducer< T, TResult > Class Template Reference

#include <reduce.h>

Inheritance diagram for bdm::experimental::GenericReducer< T, TResult >:
[legend]
Collaboration diagram for bdm::experimental::GenericReducer< T, TResult >:
[legend]

Public Member Functions

 GenericReducer ()
 
 GenericReducer (void(agent_function)(Agent *, T *), T(*reduce_partial_results)(const SharedData< T > &), bool(*filter)(Agent *)=nullptr, TResult(*post_process)(TResult)=nullptr)
 
virtual ~GenericReducer ()=default
 
void operator() (Agent *agent) override
 
void Reset () override
 Resets the internal state between calculations. More...
 
TResult GetResult () override
 
Reducer< TResult > * NewCopy () const override
 
- Public Member Functions inherited from bdm::experimental::Reducer< T >
 ~Reducer () override=default
 
virtual ReducerNewCopy () const=0
 
- Public Member Functions inherited from bdm::Functor< void, Agent * >
virtual ~Functor ()=default
 
virtual void operator() (TArgs... args)=0
 

Private Attributes

SharedData< T > tl_results_
 
void(* agent_function_ )(Agent *, T *) = nullptr
 
T(* reduce_partial_results_ )(const SharedData< T > &) = nullptr
 
bool(* filter_ )(Agent *) = nullptr
 
TResult(* post_process_ )(TResult) = nullptr
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GenericReducer() [1/2]

template<typename T , typename TResult = T>
bdm::experimental::GenericReducer< T, TResult >::GenericReducer ( )
inline

Definition at line 78 of file reduce.h.

◆ GenericReducer() [2/2]

template<typename T , typename TResult = T>
bdm::experimental::GenericReducer< T, TResult >::GenericReducer ( void(agent_function)(Agent *, T *)  ,
T(*)(const SharedData< T > &)  reduce_partial_results,
bool(*)(Agent *)  filter = nullptr,
TResult(*)(TResult)  post_process = nullptr 
)
inline

Definition at line 80 of file reduce.h.

◆ ~GenericReducer()

template<typename T , typename TResult = T>
virtual bdm::experimental::GenericReducer< T, TResult >::~GenericReducer ( )
virtualdefault

Member Function Documentation

◆ GetResult()

template<typename T , typename TResult = T>
TResult bdm::experimental::GenericReducer< T, TResult >::GetResult ( )
inlineoverridevirtual

Implements bdm::experimental::Reducer< T >.

Definition at line 111 of file reduce.h.

◆ NewCopy()

template<typename T , typename TResult = T>
Reducer<TResult>* bdm::experimental::GenericReducer< T, TResult >::NewCopy ( ) const
inlineoverride

Definition at line 119 of file reduce.h.

◆ operator()()

template<typename T , typename TResult = T>
void bdm::experimental::GenericReducer< T, TResult >::operator() ( Agent agent)
inlineoverride

Definition at line 97 of file reduce.h.

◆ Reset()

template<typename T , typename TResult = T>
void bdm::experimental::GenericReducer< T, TResult >::Reset ( )
inlineoverridevirtual

Resets the internal state between calculations.

Implements bdm::experimental::Reducer< T >.

Definition at line 104 of file reduce.h.

Member Data Documentation

◆ agent_function_

template<typename T , typename TResult = T>
void(* bdm::experimental::GenericReducer< T, TResult >::agent_function_) (Agent *, T *) = nullptr
private

Definition at line 125 of file reduce.h.

◆ filter_

template<typename T , typename TResult = T>
bool(* bdm::experimental::GenericReducer< T, TResult >::filter_) (Agent *) = nullptr
private

Definition at line 127 of file reduce.h.

◆ post_process_

template<typename T , typename TResult = T>
TResult(* bdm::experimental::GenericReducer< T, TResult >::post_process_) (TResult) = nullptr
private

Definition at line 128 of file reduce.h.

◆ reduce_partial_results_

template<typename T , typename TResult = T>
T(* bdm::experimental::GenericReducer< T, TResult >::reduce_partial_results_) (const SharedData< T > &) = nullptr
private

Definition at line 126 of file reduce.h.

◆ tl_results_

template<typename T , typename TResult = T>
SharedData<T> bdm::experimental::GenericReducer< T, TResult >::tl_results_
private

Definition at line 124 of file reduce.h.


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