BioDynaMo
v1.05.120-25dc9790
|
Go to the documentation of this file.
15 #ifndef CORE_ANALYSIS_REDUCE_H_
16 #define CORE_ANALYSIS_REDUCE_H_
29 namespace experimental {
37 template <
typename TResult>
42 virtual void Reset() = 0;
75 template <
typename T,
typename TResult = T>
82 bool (*filter)(
Agent*) =
nullptr,
83 TResult (*post_process)(TResult) =
nullptr)
134 #if (!defined(__CLING__) || defined(__ROOTCLING__)) && defined(USE_DICT)
138 template <
typename T,
typename TResult>
140 if (R__b.IsReading()) {
141 R__b.ReadClassBuffer(GenericReducer::Class(),
this);
144 this->agent_function_ =
reinterpret_cast<void (*)(
Agent*, T*)
>(l);
146 this->reduce_partial_results_ =
149 this->filter_ =
reinterpret_cast<bool (*)(
Agent*)
>(l);
151 this->post_process_ =
reinterpret_cast<TResult (*)(TResult)
>(l);
153 R__b.WriteClassBuffer(GenericReducer::Class(),
this);
154 Long64_t l =
reinterpret_cast<Long64_t
>(this->agent_function_);
156 l =
reinterpret_cast<Long64_t
>(this->reduce_partial_results_);
158 l =
reinterpret_cast<Long64_t
>(this->filter_);
160 l =
reinterpret_cast<Long64_t
>(this->post_process_);
165 #endif // !defined(__CLING__) || defined(__ROOTCLING__)
182 template <
typename T>
190 for (
auto& el : tl_results) {
198 agent_functor(agent, &(tl_results[tid]));
203 return reduce_partial_results(tl_results);
234 template <
typename TResult = u
int64_t>
240 Counter(
bool (*condition)(
Agent*), TResult (*post_process)(TResult) =
nullptr)
263 auto combined =
static_cast<TResult
>(sum(this->
tl_results_));
281 #if (!defined(__CLING__) || defined(__ROOTCLING__)) && defined(USE_DICT)
285 template <
typename TResult>
287 if (R__b.IsReading()) {
288 R__b.ReadClassBuffer(Counter::Class(),
this);
291 this->condition_ =
reinterpret_cast<bool (*)(
Agent*)
>(l);
293 this->post_process_ =
reinterpret_cast<TResult (*)(TResult)
>(l);
295 R__b.WriteClassBuffer(Counter::Class(),
this);
296 Long64_t l =
reinterpret_cast<Long64_t
>(this->condition_);
298 l =
reinterpret_cast<Long64_t
>(this->post_process_);
303 #endif // !defined(__CLING__) || defined(__ROOTCLING__)
323 for (
auto& el : tl_results) {
331 if (condition(agent)) {
339 return sum(tl_results);
345 #endif // CORE_ANALYSIS_REDUCE_H_
TResult(* post_process_)(TResult)
virtual ~Counter()=default
TResult(* post_process_)(TResult)
static ThreadInfo * GetInstance()
The SharedData class avoids false sharing between threads.
TResult GetResult() override
void(* agent_function_)(Agent *, T *)
~Reducer() override=default
SharedData< T > tl_results_
TResult GetResult() override
void Reset() override
Resets the internal state between calculations.
#define BDM_CLASS_DEF_OVERRIDE(class_name, class_version_id)
T Reduce(Simulation *sim, Functor< void, Agent *, T * > &agent_functor, Functor< T, const SharedData< T > & > &reduce_partial_results, Functor< bool, Agent * > *filter=nullptr)
void operator()(Agent *agent) override
void resize(size_t new_size)
Resize the SharedData.data_ vector.
LambdaFunctor< decltype(&TLambda::operator())> L2F(const TLambda &l)
Contains code required by all agents.
GenericReducer(void(agent_function)(Agent *, T *), T(*reduce_partial_results)(const SharedData< T > &), bool(*filter)(Agent *)=nullptr, TResult(*post_process)(TResult)=nullptr)
#define BDM_CLASS_DEF(class_name, class_version_id)
Forward all calls to BDM_NULL_CLASS_DEF.
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
virtual ~GenericReducer()=default
uint64_t Count(Simulation *sim, Functor< bool, Agent * > &condition, Functor< bool, Agent * > *filter=nullptr)
SharedData< uint64_t > tl_results_
virtual Reducer * NewCopy() const =0
bool(* condition_)(Agent *)
Counter(bool(*condition)(Agent *), TResult(*post_process)(TResult)=nullptr)
void Reset() override
Resets the internal state between calculations.
T(* reduce_partial_results_)(const SharedData< T > &)
virtual void ForEachAgentParallel(Functor< void, Agent * > &function, Functor< bool, Agent * > *filter=nullptr)
virtual void Reset()=0
Resets the internal state between calculations.
Counter()
Required for IO.
Reducer< TResult > * NewCopy() const override
void operator()(Agent *agent) override
Reducer< TResult > * NewCopy() const override
int GetMyThreadId() const
virtual TResult GetResult()=0