Loading...
Searching...
No Matches
cpuTimeCxx.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2018-2024 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::cpuTimeCxx
28
29Description
30 Starts timing CPU usage and return elapsed time from start.
31
32See also
33 clockTime
34
35SourceFiles
36 cpuTimeCxx.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_cpuTimeCxx_H
41#define Foam_cpuTimeCxx_H
42
43#include <ctime>
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
50/*---------------------------------------------------------------------------*\
51 Class cpuTimeCxx Declaration
52\*---------------------------------------------------------------------------*/
53
54class cpuTimeCxx
55{
56 //- Time structure used, with additional methods
57 struct value_type
58 {
59 std::clock_t value;
60
61 //- Construct with the current clock time
62 value_type();
63
64 //- Update with the current clock time
65 void update();
66 };
67
68
69 // Private Data
70
71 //- Start time, at the time of construction
72 value_type start_;
73
74 //- Last time when elapsedCpuTime or cpuTimeIncrement was called.
75 //- Also affected by resetCpuTime and resetCpuTimeIncrement.
76 mutable value_type last_;
77
78
79 // Private Member Functions
80
81 //- Difference between two times (a - b)
82 static inline double diff(const value_type& a, const value_type& b);
83
84
85public:
86
87 // Constructors
88
89 //- Construct with the current clock time
90 cpuTimeCxx();
91
92
93 // Member Functions
94
95 //- Reset to use the current time for the start and increment points
96 void resetCpuTime();
97
98 //- Reset to use the current time for the increment point
99 void resetCpuTimeIncrement() const;
100
101 //- Return CPU time (in seconds) from the start
102 double elapsedCpuTime() const;
103
104 //- Return CPU time [seconds] since last call to cpuTimeIncrement(),
105 //- resetCpuTimeIncrement().
106 double cpuTimeIncrement() const;
107};
108
109
110// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111
112} // End namespace Foam
113
114// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115
116#endif
117
118// ************************************************************************* //
void resetCpuTime()
Reset to use the current time for the start and increment points.
Definition cpuTimeCxx.C:54
void resetCpuTimeIncrement() const
Reset to use the current time for the increment point.
Definition cpuTimeCxx.C:61
cpuTimeCxx()
Construct with the current clock time.
Definition cpuTimeCxx.C:39
double cpuTimeIncrement() const
Return CPU time [seconds] since last call to cpuTimeIncrement(), resetCpuTimeIncrement().
Definition cpuTimeCxx.C:74
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
Definition cpuTimeCxx.C:67
mesh update()
Namespace for OpenFOAM.
volScalarField & b