diff --git a/etc/controlDict b/etc/controlDict index fd1f583ca..4868acff5 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -32,10 +32,11 @@ Documentation InfoSwitches { - writePrecision 6; - writeJobInfo 0; - writeDictionaries 0; - writeOptionalEntries 0; + writePrecision 6; + writeJobControl 0; + writeJobInfo 0; + writeDictionaries 0; + writeOptionalEntries 0; // Allow case-supplied C++ code (#codeStream, codedFixedValue) allowSystemOperations 1; diff --git a/src/OSspecific/POSIX/signals/sigFpe.C b/src/OSspecific/POSIX/signals/sigFpe.C index 848510361..3eaedd4f9 100644 --- a/src/OSspecific/POSIX/signals/sigFpe.C +++ b/src/OSspecific/POSIX/signals/sigFpe.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ License #include "sigFpe.H" #include "error.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "OSspecific.H" #include "IOstreams.H" @@ -98,7 +98,7 @@ void Foam::sigFpe::sigHandler(int) } // Update jobInfo file - jobInfo.signalEnd(); + jobInfo_.signalEnd(); error::printStack(Perr); diff --git a/src/OSspecific/POSIX/signals/sigInt.C b/src/OSspecific/POSIX/signals/sigInt.C index 4feb986a1..0412e8cac 100644 --- a/src/OSspecific/POSIX/signals/sigInt.C +++ b/src/OSspecific/POSIX/signals/sigInt.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ License #include "sigInt.H" #include "error.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "IOstreams.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -46,7 +46,7 @@ void Foam::sigInt::sigHandler(int) } // Update jobInfo file - jobInfo.signalEnd(); + jobInfo_.signalEnd(); // Throw signal (to old handler) raise(SIGINT); diff --git a/src/OSspecific/POSIX/signals/sigQuit.C b/src/OSspecific/POSIX/signals/sigQuit.C index c079639db..959168c1b 100644 --- a/src/OSspecific/POSIX/signals/sigQuit.C +++ b/src/OSspecific/POSIX/signals/sigQuit.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ License #include "sigQuit.H" #include "error.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "IOstreams.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -46,7 +46,7 @@ void Foam::sigQuit::sigHandler(int) } // Update jobInfo file - jobInfo.signalEnd(); + jobInfo_.signalEnd(); error::printStack(Perr); diff --git a/src/OSspecific/POSIX/signals/sigSegv.C b/src/OSspecific/POSIX/signals/sigSegv.C index 513af5de2..69c0c04fc 100644 --- a/src/OSspecific/POSIX/signals/sigSegv.C +++ b/src/OSspecific/POSIX/signals/sigSegv.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ License #include "sigSegv.H" #include "error.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "IOstreams.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -46,7 +46,7 @@ void Foam::sigSegv::sigHandler(int) } // Update jobInfo file - jobInfo.signalEnd(); + jobInfo_.signalEnd(); error::printStack(Perr); diff --git a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C index 9808f91c1..d9b28c5a2 100644 --- a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C +++ b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ License #include "sigStopAtWriteNow.H" #include "error.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "IOstreams.H" #include "Time.H" @@ -95,7 +95,7 @@ void Foam::sigStopAtWriteNow::sigHandler(int) } // Update jobInfo file - jobInfo.signalEnd(); + jobInfo_.signalEnd(); Info<< "sigStopAtWriteNow :" << " setting up write and stop at end of the next iteration" diff --git a/src/OSspecific/POSIX/signals/sigWriteNow.C b/src/OSspecific/POSIX/signals/sigWriteNow.C index c226ff6e1..d7e5c42b8 100644 --- a/src/OSspecific/POSIX/signals/sigWriteNow.C +++ b/src/OSspecific/POSIX/signals/sigWriteNow.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ License #include "sigWriteNow.H" #include "error.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "IOstreams.H" #include "Time.H" diff --git a/src/OpenFOAM/db/error/IOerror.C b/src/OpenFOAM/db/error/IOerror.C index 76974fbf8..aa8ceff1f 100644 --- a/src/OpenFOAM/db/error/IOerror.C +++ b/src/OpenFOAM/db/error/IOerror.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,9 +27,8 @@ License #include "OStringStream.H" #include "fileName.H" #include "dictionary.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "Pstream.H" -#include "JobInfo.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -123,7 +122,7 @@ void Foam::IOerror::SafeFatalIOError const string& msg ) { - if (JobInfo::constructed) + if (jobInfo::constructed) { FatalIOError ( @@ -170,10 +169,10 @@ Foam::IOerror::operator Foam::dictionary() const void Foam::IOerror::exit(const int) { - if (!throwExceptions_ && JobInfo::constructed) + if (!throwExceptions_ && jobInfo::constructed) { - jobInfo.add("FatalIOError", operator dictionary()); - jobInfo.exit(); + jobInfo_.add("FatalIOError", operator dictionary()); + jobInfo_.exit(); } if (abort_) @@ -211,10 +210,10 @@ void Foam::IOerror::exit(const int) void Foam::IOerror::abort() { - if (!throwExceptions_ && JobInfo::constructed) + if (!throwExceptions_ && jobInfo::constructed) { - jobInfo.add("FatalIOError", operator dictionary()); - jobInfo.abort(); + jobInfo_.add("FatalIOError", operator dictionary()); + jobInfo_.abort(); } if (abort_) diff --git a/src/OpenFOAM/db/error/error.C b/src/OpenFOAM/db/error/error.C index 91ec55632..af93c54d1 100644 --- a/src/OpenFOAM/db/error/error.C +++ b/src/OpenFOAM/db/error/error.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,7 +27,7 @@ License #include "OStringStream.H" #include "fileName.H" #include "dictionary.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "Pstream.H" #include "OSspecific.H" @@ -167,10 +167,10 @@ Foam::string Foam::error::message() const void Foam::error::exit(const int errNo) { - if (!throwExceptions_ && JobInfo::constructed) + if (!throwExceptions_ && jobInfo::constructed) { - jobInfo.add("FatalError", operator dictionary()); - jobInfo.exit(); + jobInfo_.add("FatalError", operator dictionary()); + jobInfo_.exit(); } if (abort_) @@ -208,10 +208,10 @@ void Foam::error::exit(const int errNo) void Foam::error::abort() { - if (!throwExceptions_ && JobInfo::constructed) + if (!throwExceptions_ && jobInfo::constructed) { - jobInfo.add("FatalError", operator dictionary()); - jobInfo.abort(); + jobInfo_.add("FatalError", operator dictionary()); + jobInfo_.abort(); } if (abort_) diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index b94e0ee46..22d09ec22 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,7 @@ License #include "IFstream.H" #include "dictionary.H" #include "IOobject.H" -#include "JobInfo.H" +#include "jobInfo.H" #include "labelList.H" #include "regIOobject.H" #include "dynamicCode.H" @@ -561,15 +561,15 @@ void Foam::argList::parse << "PID : " << pid() << endl; } - jobInfo.add("startDate", dateString); - jobInfo.add("startTime", timeString); - jobInfo.add("userName", userName()); - jobInfo.add("foamVersion", word(FOAMversion)); - jobInfo.add("code", executable_); - jobInfo.add("argList", argListStr_); - jobInfo.add("currentDir", cwd()); - jobInfo.add("PPID", ppid()); - jobInfo.add("PGID", pgid()); + jobInfo_.add("startDate", dateString); + jobInfo_.add("startTime", timeString); + jobInfo_.add("userName", userName()); + jobInfo_.add("foamVersion", word(FOAMversion)); + jobInfo_.add("code", executable_); + jobInfo_.add("argList", argListStr_); + jobInfo_.add("currentDir", cwd()); + jobInfo_.add("PPID", ppid()); + jobInfo_.add("PGID", pgid()); // Add build information - only use the first word { @@ -579,7 +579,7 @@ void Foam::argList::parse { build.resize(found); } - jobInfo.add("foamBuild", build); + jobInfo_.add("foamBuild", build); } } @@ -884,18 +884,18 @@ void Foam::argList::parse if (initialise) { - jobInfo.add("root", rootPath_); - jobInfo.add("case", globalCase_); - jobInfo.add("nProcs", nProcs); + jobInfo_.add("root", rootPath_); + jobInfo_.add("case", globalCase_); + jobInfo_.add("nProcs", nProcs); if (slaveProcs.size()) { - jobInfo.add("slaves", slaveProcs); + jobInfo_.add("slaves", slaveProcs); } if (roots.size()) { - jobInfo.add("roots", roots); + jobInfo_.add("roots", roots); } - jobInfo.write(); + jobInfo_.write(rootPath_/globalCase_); // Switch on signal trapping. We have to wait until after Pstream::init // since this sets up its own ones. @@ -954,7 +954,7 @@ void Foam::argList::parse Foam::argList::~argList() { - jobInfo.end(); + jobInfo_.end(); // Delete file handler to flush any remaining IO autoPtr dummy(nullptr); diff --git a/src/OpenFOAM/global/global.Cver b/src/OpenFOAM/global/global.Cver index a86849555..491aa4bdf 100644 --- a/src/OpenFOAM/global/global.Cver +++ b/src/OpenFOAM/global/global.Cver @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,8 +54,8 @@ const char* const Foam::FOAMbuild = "BUILD_STRING"; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "JobInfo.H" -bool Foam::JobInfo::constructed(false); +#include "jobInfo.H" +bool Foam::jobInfo::constructed(false); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Global error definitions (initialised by construction) @@ -94,6 +94,6 @@ bool Foam::JobInfo::constructed(false); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Create the jobInfo file in the $FOAM_JOB_DIR/runningJobs directory -#include "JobInfo.C" +#include "jobInfo.C" // ************************************************************************* // diff --git a/src/OpenFOAM/global/JobInfo/JobInfo.C b/src/OpenFOAM/global/jobInfo/jobInfo.C similarity index 57% rename from src/OpenFOAM/global/JobInfo/JobInfo.C rename to src/OpenFOAM/global/jobInfo/jobInfo.C index 7d1721884..3838c12f0 100644 --- a/src/OpenFOAM/global/JobInfo/JobInfo.C +++ b/src/OpenFOAM/global/jobInfo/jobInfo.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "JobInfo.H" +#include "jobInfo.H" #include "OSspecific.H" #include "clock.H" #include "OFstream.H" @@ -31,50 +31,71 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -bool Foam::JobInfo::writeJobInfo(Foam::debug::infoSwitch("writeJobInfo", 0)); -Foam::JobInfo Foam::jobInfo; +bool Foam::jobInfo::writeJobControl +( + Foam::debug::infoSwitch("writeJobControl", 0) +); + +bool Foam::jobInfo::writeJobInfo +( + Foam::debug::infoSwitch("writeJobInfo", 0) +); + +Foam::jobInfo Foam::jobInfo_; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::JobInfo::JobInfo() +Foam::jobInfo::jobInfo() : runningJobPath_(), finishedJobPath_(), cpuTime_() { - name() = "JobInfo"; + name() = "jobInfo"; - if (writeJobInfo && Pstream::master()) + if (Pstream::master()) { - string baseDir = getEnv("FOAM_JOB_DIR"); - string jobFile = hostName() + '.' + Foam::name(pid()); - - fileName runningDir(baseDir/"runningJobs"); - fileName finishedDir(baseDir/"finishedJobs"); - - runningJobPath_ = runningDir/jobFile; - finishedJobPath_ = finishedDir/jobFile; - - if (baseDir.empty()) + if (writeJobControl) { - FatalErrorInFunction - << "Cannot get JobInfo directory $FOAM_JOB_DIR" - << Foam::exit(FatalError); + string baseDir = getEnv("FOAM_JOB_DIR"); + string jobFile = hostName() + '.' + Foam::name(pid()); + + fileName runningDir(baseDir/"runningJobs"); + fileName finishedDir(baseDir/"finishedJobs"); + + runningJobPath_ = runningDir/jobFile; + finishedJobPath_ = finishedDir/jobFile; + + if (baseDir.empty()) + { + FatalErrorInFunction + << "Cannot get jobInfo directory $FOAM_JOB_DIR" + << Foam::exit(FatalError); + } + + if (!isDir(runningDir) && !mkDir(runningDir)) + { + FatalErrorInFunction + << "Cannot make jobInfo directory " << runningDir + << Foam::exit(FatalError); + } + + if (!isDir(finishedDir) && !mkDir(finishedDir)) + { + FatalErrorInFunction + << "Cannot make jobInfo directory " << finishedDir + << Foam::exit(FatalError); + } + + writeJobInfo = true; } - - if (!isDir(runningDir) && !mkDir(runningDir)) + else if (writeJobInfo) { - FatalErrorInFunction - << "Cannot make JobInfo directory " << runningDir - << Foam::exit(FatalError); - } + string jobFile = name() + '.' + Foam::name(pid()); - if (!isDir(finishedDir) && !mkDir(finishedDir)) - { - FatalErrorInFunction - << "Cannot make JobInfo directory " << finishedDir - << Foam::exit(FatalError); + runningJobPath_ = jobFile; + finishedJobPath_ = jobFile; } } @@ -84,7 +105,7 @@ Foam::JobInfo::JobInfo() // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -Foam::JobInfo::~JobInfo() +Foam::jobInfo::~jobInfo() { if (writeJobInfo && constructed && Pstream::master()) { @@ -97,7 +118,7 @@ Foam::JobInfo::~JobInfo() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::JobInfo::write(Ostream& os) const +bool Foam::jobInfo::write(Ostream& os) const { if (writeJobInfo && Pstream::master()) { @@ -118,14 +139,20 @@ bool Foam::JobInfo::write(Ostream& os) const } -void Foam::JobInfo::write() const +void Foam::jobInfo::write(const fileName& casePath) const { if (writeJobInfo && Pstream::master()) { + if (!writeJobControl) + { + runningJobPath_ = casePath/runningJobPath_; + finishedJobPath_ = casePath/finishedJobPath_; + } + if (!write(OFstream(runningJobPath_)())) { FatalErrorInFunction - << "Failed to write to JobInfo file " + << "Failed to write to jobInfo file " << runningJobPath_ << Foam::exit(FatalError); } @@ -133,7 +160,7 @@ void Foam::JobInfo::write() const } -void Foam::JobInfo::end(const word& terminationType) +void Foam::jobInfo::end(const word& terminationType) { if (writeJobInfo && constructed && Pstream::master()) { @@ -154,27 +181,27 @@ void Foam::JobInfo::end(const word& terminationType) } -void Foam::JobInfo::end() +void Foam::jobInfo::end() { end("normal"); } -void Foam::JobInfo::exit() +void Foam::jobInfo::exit() { end("exit"); } -void Foam::JobInfo::abort() +void Foam::jobInfo::abort() { end("abort"); } -void Foam::JobInfo::signalEnd() const +void Foam::jobInfo::signalEnd() const { - if (writeJobInfo && constructed && Pstream::master()) + if (writeJobControl && constructed && Pstream::master()) { mv(runningJobPath_, finishedJobPath_); } diff --git a/src/OpenFOAM/global/JobInfo/JobInfo.H b/src/OpenFOAM/global/jobInfo/jobInfo.H similarity index 79% rename from src/OpenFOAM/global/JobInfo/JobInfo.H rename to src/OpenFOAM/global/jobInfo/jobInfo.H index 5549af627..be1f56e95 100644 --- a/src/OpenFOAM/global/JobInfo/JobInfo.H +++ b/src/OpenFOAM/global/jobInfo/jobInfo.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . Class - Foam::JobInfo + Foam::jobInfo Description Helper class for recording information about run/finished jobs. @@ -32,12 +32,12 @@ Description - $FOAM_JOB_DIR/finishedJobs SourceFiles - JobInfo.C + jobInfo.C \*---------------------------------------------------------------------------*/ -#ifndef JobInfo_H -#define JobInfo_H +#ifndef jobInfo_H +#define jobInfo_H #include "dictionary.H" #include "fileName.H" @@ -49,17 +49,18 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class JobInfo Declaration + Class jobInfo Declaration \*---------------------------------------------------------------------------*/ -class JobInfo +class jobInfo : public dictionary { // Private data - fileName runningJobPath_; - fileName finishedJobPath_; - cpuTime cpuTime_; + + mutable fileName runningJobPath_; + mutable fileName finishedJobPath_; + cpuTime cpuTime_; // Private Member Functions @@ -70,35 +71,34 @@ class JobInfo public: static bool constructed; + static bool writeJobControl; static bool writeJobInfo; // Constructors //- Construct null - JobInfo(); + jobInfo(); //- Destructor - ~JobInfo(); + ~jobInfo(); // Member Functions - // Write + void write(const fileName& casePath) const; - void write() const; + void end(); - void end(); + void exit(); - void exit(); + void abort(); - void abort(); - - void signalEnd() const; + void signalEnd() const; }; -extern JobInfo jobInfo; +extern jobInfo jobInfo_; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //