Loading...
Searching...
No Matches
cpuTimePosix.C
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) 2011-2014 OpenFOAM Foundation
9 Copyright (C) 2018 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
29#include "cpuTimePosix.H"
30#include <unistd.h>
31
32// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
33
34// Clock-ticks per second
35static const long clockTicks_(sysconf(_SC_CLK_TCK));
36
37
38// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39
40inline double Foam::cpuTimePosix::diff(const value_type& a, const value_type& b)
41{
42 return
43 (
44 double((a.tms_utime + a.tms_stime) - (b.tms_utime + b.tms_stime))
46 );
47}
48
49
50// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52Foam::cpuTimePosix::value_type::value_type()
53{
54 update();
55}
56
57
59:
60 start_(),
61 last_(start_)
62{}
63
64
65// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67void Foam::cpuTimePosix::value_type::update()
68{
69 ::times(this);
70}
71
72
74{
75 last_.update();
76 start_ = last_;
77}
78
81{
82 last_.update();
83}
84
85
87{
88 last_.update();
89 return diff(last_, start_);
90}
91
92
94{
95 const value_type prev(last_);
96 last_.update();
97 return diff(last_, prev);
98}
99
100
101// ************************************************************************* //
void resetCpuTime()
Reset to use the current time for the start time.
void resetCpuTimeIncrement() const
Reset to use the current time for the increment point.
cpuTimePosix()
Construct with the current clock time.
double cpuTimeIncrement() const
Return CPU time [seconds] since last call to cpuTimeIncrement(), resetCpuTimeIncrement().
double elapsedCpuTime() const
Return CPU time [seconds] from the start.
mesh update()
static const long clockTicks_(sysconf(_SC_CLK_TCK))
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition triad.C:373
volScalarField & b