1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "OSspecific.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 Foam::debug::infoSwitch
35 Foam::JobInfo::writeJobInfo
41 Foam::JobInfo Foam::jobInfo;
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 Foam::JobInfo::JobInfo()
55 if (writeJobInfo && Pstream::master())
57 string baseDir = getEnv("FOAM_JOB_DIR");
58 string jobFile = hostName() + '.' + Foam::name(pid());
60 fileName runningDir(baseDir/"runningJobs");
61 fileName finishedDir(baseDir/"finishedJobs");
63 runningJobPath_ = runningDir/jobFile;
64 finishedJobPath_ = finishedDir/jobFile;
68 FatalErrorIn("JobInfo::JobInfo()")
69 << "Cannot get JobInfo directory $FOAM_JOB_DIR"
70 << Foam::exit(FatalError);
73 if (!isDir(runningDir) && !mkDir(runningDir))
75 FatalErrorIn("JobInfo::JobInfo()")
76 << "Cannot make JobInfo directory " << runningDir
77 << Foam::exit(FatalError);
80 if (!isDir(finishedDir) && !mkDir(finishedDir))
82 FatalErrorIn("JobInfo::JobInfo()")
83 << "Cannot make JobInfo directory " << finishedDir
84 << Foam::exit(FatalError);
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 Foam::JobInfo::~JobInfo()
96 if (writeJobInfo && constructed && Pstream::master())
98 mv(runningJobPath_, finishedJobPath_);
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 bool Foam::JobInfo::write(Ostream& os) const
109 if (writeJobInfo && Pstream::master())
113 dictionary::write(os, false);
128 void Foam::JobInfo::write() const
130 if (writeJobInfo && Pstream::master())
132 if (!write(OFstream(runningJobPath_)()))
134 FatalErrorIn("JobInfo::write() const")
135 << "Failed to write to JobInfo file "
137 << Foam::exit(FatalError);
143 void Foam::JobInfo::end(const word& terminationType)
145 if (writeJobInfo && constructed && Pstream::master())
147 add("cpuTime", cpuTime_.elapsedCpuTime());
148 add("endDate", clock::date());
149 add("endTime", clock::clockTime());
151 if (!found("termination"))
153 add("termination", terminationType);
157 write(OFstream(finishedJobPath_)());
164 void Foam::JobInfo::end()
170 void Foam::JobInfo::exit()
176 void Foam::JobInfo::abort()
182 void Foam::JobInfo::signalEnd() const
184 if (writeJobInfo && constructed && Pstream::master())
186 mv(runningJobPath_, finishedJobPath_);
193 // ************************************************************************* //