1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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 bool Foam::JobInfo::writeJobInfo(Foam::debug::infoSwitch("writeJobInfo", 0));
35 Foam::JobInfo Foam::jobInfo;
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 Foam::JobInfo::JobInfo()
49 if (writeJobInfo && Pstream::master())
51 string baseDir = getEnv("FOAM_JOB_DIR");
52 string jobFile = hostName() + '.' + Foam::name(pid());
54 fileName runningDir(baseDir/"runningJobs");
55 fileName finishedDir(baseDir/"finishedJobs");
57 runningJobPath_ = runningDir/jobFile;
58 finishedJobPath_ = finishedDir/jobFile;
62 FatalErrorIn("JobInfo::JobInfo()")
63 << "Cannot get JobInfo directory $FOAM_JOB_DIR"
64 << Foam::exit(FatalError);
67 if (!isDir(runningDir) && !mkDir(runningDir))
69 FatalErrorIn("JobInfo::JobInfo()")
70 << "Cannot make JobInfo directory " << runningDir
71 << Foam::exit(FatalError);
74 if (!isDir(finishedDir) && !mkDir(finishedDir))
76 FatalErrorIn("JobInfo::JobInfo()")
77 << "Cannot make JobInfo directory " << finishedDir
78 << Foam::exit(FatalError);
86 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 Foam::JobInfo::~JobInfo()
90 if (writeJobInfo && constructed && Pstream::master())
92 mv(runningJobPath_, finishedJobPath_);
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 bool Foam::JobInfo::write(Ostream& os) const
103 if (writeJobInfo && Pstream::master())
107 dictionary::write(os, false);
122 void Foam::JobInfo::write() const
124 if (writeJobInfo && Pstream::master())
126 if (!write(OFstream(runningJobPath_)()))
128 FatalErrorIn("JobInfo::write() const")
129 << "Failed to write to JobInfo file "
131 << Foam::exit(FatalError);
137 void Foam::JobInfo::end(const word& terminationType)
139 if (writeJobInfo && constructed && Pstream::master())
141 add("cpuTime", cpuTime_.elapsedCpuTime());
142 add("endDate", clock::date());
143 add("endTime", clock::clockTime());
145 if (!found("termination"))
147 add("termination", terminationType);
151 write(OFstream(finishedJobPath_)());
158 void Foam::JobInfo::end()
164 void Foam::JobInfo::exit()
170 void Foam::JobInfo::abort()
176 void Foam::JobInfo::signalEnd() const
178 if (writeJobInfo && constructed && Pstream::master())
180 mv(runningJobPath_, finishedJobPath_);
187 // ************************************************************************* //