1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "OSspecific.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 bool Foam::JobInfo::writeJobInfo(Foam::debug::infoSwitch("writeJobInfo", 0));
36 Foam::JobInfo Foam::jobInfo;
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 Foam::JobInfo::JobInfo()
50 if (writeJobInfo && Pstream::master())
52 string baseDir = getEnv("FOAM_JOB_DIR");
53 string jobFile = hostName() + '.' + Foam::name(pid());
55 fileName runningDir(baseDir/"runningJobs");
56 fileName finishedDir(baseDir/"finishedJobs");
58 runningJobPath_ = runningDir/jobFile;
59 finishedJobPath_ = finishedDir/jobFile;
63 FatalErrorIn("JobInfo::JobInfo()")
64 << "Cannot get JobInfo directory $FOAM_JOB_DIR"
65 << Foam::exit(FatalError);
68 if (!isDir(runningDir) && !mkDir(runningDir))
70 FatalErrorIn("JobInfo::JobInfo()")
71 << "Cannot make JobInfo directory " << runningDir
72 << Foam::exit(FatalError);
75 if (!isDir(finishedDir) && !mkDir(finishedDir))
77 FatalErrorIn("JobInfo::JobInfo()")
78 << "Cannot make JobInfo directory " << finishedDir
79 << Foam::exit(FatalError);
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 Foam::JobInfo::~JobInfo()
91 if (writeJobInfo && constructed && Pstream::master())
93 mv(runningJobPath_, finishedJobPath_);
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 bool Foam::JobInfo::write(Ostream& os) const
104 if (writeJobInfo && Pstream::master())
108 dictionary::write(os, false);
123 void Foam::JobInfo::write() const
125 if (writeJobInfo && Pstream::master())
127 if (!write(OFstream(runningJobPath_)()))
129 FatalErrorIn("JobInfo::write() const")
130 << "Failed to write to JobInfo file "
132 << Foam::exit(FatalError);
138 void Foam::JobInfo::end(const word& terminationType)
140 if (writeJobInfo && constructed && Pstream::master())
142 add("cpuTime", cpuTime_.elapsedCpuTime());
143 add("endDate", clock::date());
144 add("endTime", clock::clockTime());
146 if (!found("termination"))
148 add("termination", terminationType);
152 write(OFstream(finishedJobPath_)());
159 void Foam::JobInfo::end()
165 void Foam::JobInfo::exit()
171 void Foam::JobInfo::abort()
177 void Foam::JobInfo::signalEnd() const
179 if (writeJobInfo && constructed && Pstream::master())
181 mv(runningJobPath_, finishedJobPath_);
188 // ************************************************************************* //