BioDynaMo  v1.05.119-a4ff3934
op_timer.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_OPERATION_OP_TIMER_H_
16 #define CORE_OPERATION_OP_TIMER_H_
17 
18 #include <string>
19 #include <utility>
20 #include "core/simulation.h"
21 #include "core/util/timing.h"
22 
23 namespace bdm {
24 
26 template <typename TOp>
27 class OpTimer {
28  public:
29  explicit OpTimer(std::string timer_msg) : timer_msg_(std::move(timer_msg)) {}
30  explicit OpTimer(std::string timer_msg, const TOp& op)
31  : timer_msg_(std::move(timer_msg)), operation_(op) {}
32 
33  template <typename Container>
34  void operator()(Container* cells, uint16_t numa_node, uint16_t type_idx) {
35  auto* param = Simulation::GetActive()->GetParam();
36  auto* agg = Simulation::GetActive()->GetScheduler()->GetOpTimes();
37  if (param->statistics) {
38  Timing timer(timer_msg_, agg);
39  operation_(cells, numa_node, type_idx);
40  } else {
41  operation_(cells, numa_node, type_idx);
42  }
43  }
44 
45  TOp* operator->() { return &operation_; }
46  const TOp* operator->() const { return &operation_; }
47 
48  private:
49  std::string timer_msg_;
51 };
52 
53 } // namespace bdm
54 
55 #endif // CORE_OPERATION_OP_TIMER_H_
bdm::OpTimer::operator->
TOp * operator->()
Definition: op_timer.h:45
timing.h
bdm::OpTimer::operation_
TOp operation_
Definition: op_timer.h:50
bdm
Definition: agent.cc:39
bdm::Scheduler::GetOpTimes
TimingAggregator * GetOpTimes()
Definition: scheduler.cc:162
bdm::OpTimer::OpTimer
OpTimer(std::string timer_msg)
Definition: op_timer.h:29
bdm::Timing
Definition: timing.h:29
bdm::Simulation::GetScheduler
Scheduler * GetScheduler()
Definition: simulation.cc:262
bdm::OpTimer::operator()
void operator()(Container *cells, uint16_t numa_node, uint16_t type_idx)
Definition: op_timer.h:34
bdm::OpTimer
Decorator for Operations to measure runtime.
Definition: op_timer.h:27
bdm::OpTimer::operator->
const TOp * operator->() const
Definition: op_timer.h:46
bdm::OpTimer::OpTimer
OpTimer(std::string timer_msg, const TOp &op)
Definition: op_timer.h:30
std
Definition: agent_uid.h:117
simulation.h
bdm::Simulation::GetParam
const Param * GetParam() const
Returns the simulation parameters.
Definition: simulation.cc:254
bdm::OpTimer::timer_msg_
std::string timer_msg_
Definition: op_timer.h:49
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68