Commit fbf0b85b authored by Quentin Khan's avatar Quentin Khan

FAlgorithmTimers: change timers container type to std::map

The timers are mapped to a std::string. The basic ones (P2L, P2M, M2M,
M2P, M2L, L2L, L2P, P2P) have a constexpr definition. Any new timer can
be added by calling `Timers["timer name"];`.
parent e578efc4
......@@ -17,6 +17,11 @@
#ifndef FALGORITHMTIMERS_HPP
#define FALGORITHMTIMERS_HPP
#include <map>
#include <string>
#include "FTic.hpp"
/**
* @brief Collection of timers for FMM operators.
*
......@@ -25,56 +30,38 @@
*/
class FAlgorithmTimers{
public:
/// The timer names
enum FTimers {
P2MTimer,
M2MTimer,
M2LTimer,
L2LTimer,
L2PTimer,
P2PTimer,
NearTimer,
nbTimers ///< Timer count
};
static constexpr const char* P2MTimer = "P2M";
static constexpr const char* M2MTimer = "M2M";
static constexpr const char* M2LTimer = "M2L";
static constexpr const char* L2LTimer = "L2L";
static constexpr const char* L2PTimer = "L2P";
static constexpr const char* P2PTimer = "P2P";
static constexpr const char* M2PTimer = "M2P";
static constexpr const char* P2LTimer = "P2L";
static constexpr const char* NearTimer = "Near";
enum {nbTimers = 9};
protected:
/// Timer array
FTic Timers[nbTimers];
/// Timers
std::map<std::string, FTic> Timers;
public:
/// Constructor: resets all timers
FAlgorithmTimers()
{
for(int i = 0; i < nbTimers ; ++i){
Timers[i].reset();
}
}
FAlgorithmTimers() = default;
/// Default copy contructor
FAlgorithmTimers(const FAlgorithmTimers&) = default;
/// Default move contructor
FAlgorithmTimers(FAlgorithmTimers&&) = default;
/// Returns the timer array
const FTic * getAllTimers() const {
return Timers;
}
/// Returns the timer count
int getNbOfTimerRecorded() const {
return nbTimers;
}
/// Elapsed time between last FTic::tic() and FTic::tac() for given timer.
double getTime(FTimers OpeTimer) const{
double getTime(std::string TimerName) const{
//assert to verify size
return Timers[OpeTimer].elapsed();
return Timers.at(TimerName).elapsed();
}
/// Cumulated time between all FTic::tic() and FTic::tac() for given timer.
double getCumulatedTime(FTimers OpeTimer) const{
double getCumulatedTime(std::string TimerName) const{
//assert to verify size
return Timers[OpeTimer].cumulated();
return Timers.at(TimerName).cumulated();
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment