FAlgorithmTimers.hpp 1.77 KB
Newer Older
1
// See LICENCE file at project root
2
3
4
5

#ifndef FALGORITHMTIMERS_HPP
#define FALGORITHMTIMERS_HPP

6
7
#include <map>
#include <string>
COULAUD Olivier's avatar
COULAUD Olivier committed
8
#include <stdexcept>
9
10
11

#include "FTic.hpp"

12
13
using FTimerMap = std::map<std::string, FTic>;

14
/**
15
 * @brief Collection of timers for FMM operators.
16
 *
17
18
 * This class provide a way for the different algorithms to
 * store the time spent in each operator.
19
20
21
 */
class FAlgorithmTimers{
public:
22
23
24
25
26
27
28
29
30
    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";
31
32
    static constexpr const char* FarTimer = "Far";
    enum {nbTimers = 10};
33

34
    /// Timers
35
    FTimerMap Timers;
36

37
    /// Constructor: resets all timers
38
    FAlgorithmTimers() = default;
39

40
41
42
43
    /// Default copy contructor
    FAlgorithmTimers(const FAlgorithmTimers&) = default;
    /// Default move contructor
    FAlgorithmTimers(FAlgorithmTimers&&) = default;
44

45
    /// Elapsed time between last FTic::tic() and FTic::tac() for given timer.
46
    double getTime(std::string TimerName) const{
47
48
49
        double res = 0;
        try {
            res = Timers.at(TimerName).elapsed();
50
        } catch(std::out_of_range&) {
51
52
53
            res = 0;
        }
        return res;
54
55
    }

56
    /// Cumulated time between all FTic::tic() and FTic::tac() for given timer.
57
    double getCumulatedTime(std::string TimerName) const{
58
        //assert to verify size
59
        return Timers.at(TimerName).cumulated();
60
61
62
63
64
    }

};

#endif // FALGORITHMTIMERS_HPP