JobInfo.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) 2011 OpenFOAM Foundation
9 Copyright (C) 2017-2021 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
27Class
28 Foam::JobInfo
29
30Description
31 Helper class for recording information about run/finished jobs,
32 acts like global singleton.
33
34 Writes the following files:
35 - $FOAM_JOB_DIR/runningJobs
36 - $FOAM_JOB_DIR/finishedJobs
37
38 If FOAM_JOB_DIR is unset, defaults to ~/.OpenFOAM/jobControl
39
40Note
41 JobInfo is treated as a largely failsafe operation.
42 If the directories cannot be written to,
43 only a warning (not an error) is emitted.
44
45SourceFiles
46 JobInfo.C
47
48\*---------------------------------------------------------------------------*/
49
50#ifndef JobInfo_H
51#define JobInfo_H
52
53#include "dictionary.H"
54#include "cpuTime.H"
55
56// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57
58namespace Foam
59{
60
61/*---------------------------------------------------------------------------*\
62 Class JobInfo Declaration
63\*---------------------------------------------------------------------------*/
65class JobInfo
66:
67 public dictionary
68{
69 // Private Data
70
71 //- Full path to "running" job information file (master only)
72 fileName running_;
73
74 //- Full path to "finished" job information file (master only)
75 fileName finished_;
76
77 //- Timing information
78 cpuTime cpuTime_;
79
80
81 // Private Member Functions
82
83 //- Relocate job file from "running" to "finished" directory.
84 // Invalidates job contents, clears 'constructed'.
85 void jobEnding();
86
87 //- Add elapsed times, termination type, remove file
88 //- from "running" and create in "finished" directory.
89 // Invalidates job contents, clears 'constructed'.
90 void jobEnding(const word& terminationType);
91
92 //- No copy construct
93 JobInfo(const JobInfo&) = delete;
94
95 //- No copy assignment
96 void operator=(const JobInfo&) = delete;
97
98
99public:
100
101 //- Global value for constructed job info
102 static bool constructed;
103
104 //- Global value for writeJobInfo enabled
105 static bool writeJobInfo;
106
107
108 // Constructors
109
110 //- Default construct
111 JobInfo();
112
113
114 //- Destructor, relocates the job file from running to finished.
115 ~JobInfo();
116
117
118 // Static Member Functions
119
120 //- Disallow JobInfo by forcing writeJobInfo (InfoSwitch) off.
121 static void disable() noexcept;
122
123 //- Simple shutdown (finalize) of JobInfo
124 // Relocates the job file from "running" to "finished".
125 // Invalidates job contents, clears 'constructed'.
126 static void shutdown();
127
128 //- Exit or abort shutdown (finalize) of JobInfo
129 static void shutdown(bool isAbort);
130
131
132 // Member Functions
133
134 //- Write job info to its file in the "running" jobs directory
135 void write() const;
136
137 //- Job end with "normal" termination
138 void stop();
139
140 //- Job end with "exit" termination
141 void exit();
142
143 //- Job end with "abort" termination
144 void abort();
145
146 //- Relocate job file from "running" to "finished" directory.
147 // Invalidates job contents, clears 'constructed'.
148 void signalEnd();
149
150
151 // Housekeeping
152
153 //- Same as stop
154 void end() { stop(); }
155};
156
157
158// Job information bookkeeping (global)
159extern JobInfo jobInfo;
160
161
162// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163
164} // End namespace Foam
165
166// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167
168#endif
169
170// ************************************************************************* //
Helper class for recording information about run/finished jobs, acts like global singleton.
Definition: JobInfo.H:67
static void disable() noexcept
Disallow JobInfo by forcing writeJobInfo (InfoSwitch) off.
Definition: JobInfo.C:92
void exit()
Job end with "exit" termination.
Definition: JobInfo.C:234
void write() const
Write job info to its file in the "running" jobs directory.
Definition: JobInfo.C:214
JobInfo()
Default construct.
Definition: JobInfo.C:166
~JobInfo()
Destructor, relocates the job file from running to finished.
Definition: JobInfo.C:206
static void shutdown()
Simple shutdown (finalize) of JobInfo.
Definition: JobInfo.C:98
static bool constructed
Global value for constructed job info.
Definition: JobInfo.H:101
static bool writeJobInfo
Global value for writeJobInfo enabled.
Definition: JobInfo.H:104
void stop()
Job end with "normal" termination.
Definition: JobInfo.C:232
void end()
Same as stop.
Definition: JobInfo.H:153
void abort()
Job end with "abort" termination.
Definition: JobInfo.C:236
void signalEnd()
Relocate job file from "running" to "finished" directory.
Definition: JobInfo.C:238
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTimeCxx.H:54
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
JobInfo jobInfo
Definition: JobInfo.C:49