Commit d1bb2d68 authored by Quentin Khan's avatar Quentin Khan
Browse files

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 7e3e061d
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
#ifndef FALGORITHMTIMERS_HPP #ifndef FALGORITHMTIMERS_HPP
#define FALGORITHMTIMERS_HPP #define FALGORITHMTIMERS_HPP
#include <map>
#include <string>
#include "FTic.hpp"
/** /**
* @brief Collection of timers for FMM operators. * @brief Collection of timers for FMM operators.
* *
...@@ -25,56 +30,38 @@ ...@@ -25,56 +30,38 @@
*/ */
class FAlgorithmTimers{ class FAlgorithmTimers{
public: public:
/// The timer names static constexpr const char* P2MTimer = "P2M";
enum FTimers { static constexpr const char* M2MTimer = "M2M";
P2MTimer, static constexpr const char* M2LTimer = "M2L";
M2MTimer, static constexpr const char* L2LTimer = "L2L";
M2LTimer, static constexpr const char* L2PTimer = "L2P";
L2LTimer, static constexpr const char* P2PTimer = "P2P";
L2PTimer, static constexpr const char* M2PTimer = "M2P";
P2PTimer, static constexpr const char* P2LTimer = "P2L";
NearTimer, static constexpr const char* NearTimer = "Near";
nbTimers ///< Timer count enum {nbTimers = 9};
};
protected: /// Timers
/// Timer array std::map<std::string, FTic> Timers;
FTic Timers[nbTimers];
public:
/// Constructor: resets all timers /// Constructor: resets all timers
FAlgorithmTimers() FAlgorithmTimers() = default;
{
for(int i = 0; i < nbTimers ; ++i){
Timers[i].reset();
}
}
/// Default copy contructor /// Default copy contructor
FAlgorithmTimers(const FAlgorithmTimers&) = default; FAlgorithmTimers(const FAlgorithmTimers&) = default;
/// Default move contructor /// Default move contructor
FAlgorithmTimers(FAlgorithmTimers&&) = default; 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. /// 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 //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. /// 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 //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