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\*---------------------------------------------------------------------------*/
28
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 * * * * * * * * * * * * * * //
51
52Foam::cpuTimePosix::value_type::value_type()
53{
54 update();
55}
56
57
59:
60 start_(),
61 last_(start_)
62{}
63
64
65// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66
67void Foam::cpuTimePosix::value_type::update()
68{
69 ::times(this);
70}
71
72
74{
75 last_.update();
76 start_ = last_;
77}
78
79
81{
82 last_.update();
83 return diff(last_, start_);
84}
85
86
88{
89 const value_type prev(last_);
90 last_.update();
91 return diff(last_, prev);
92}
93
94
95// ************************************************************************* //
void resetCpuTime()
Reset to use the current time for the start time.
Definition: cpuTimePosix.C:73
cpuTimePosix()
Construct with the current clock time.
Definition: cpuTimePosix.C:58
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTimePosix.C:87
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
Definition: cpuTimePosix.C:80
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:378
volScalarField & b
Definition: createFields.H:27