ENH: default jobControl now under the '~/.OpenFOAM/jobControl' directory

- this implies that jobControl is a user-resource for OpenFOAM.
  It was previously located under $WM_PROJECT_INST_DIR/jobControl,
  but few users will have write access there.

- an unset FOAM_JOB_DIR variable is treated as "~/.OpenFOAM/jobControl",
  which can partially reduce environment clutter.

- provide argList::noJobInfo() to conveniently suppress job-info on an
  individual basis for short-running utilities (eg, foamListTimes) to
  avoid unneeded clutter.
This commit is contained in:
Mark Olesen
2017-04-03 08:28:15 +02:00
parent c341b22f9d
commit af49eaf625
14 changed files with 133 additions and 122 deletions

View File

@ -241,6 +241,7 @@ int main(int argc, char *argv[])
argList::addNote("manipulates dictionaries"); argList::addNote("manipulates dictionaries");
argList::noBanner(); argList::noBanner();
argList::noJobInfo();
argList::validArgs.append("dictionary"); argList::validArgs.append("dictionary");
argList::addBoolOption("keywords", "list keywords"); argList::addBoolOption("keywords", "list keywords");
argList::addOption("entry", "name", "report/select the named entry"); argList::addOption("entry", "name", "report/select the named entry");

View File

@ -59,6 +59,7 @@ int main(int argc, char *argv[])
timeSelector::addOptions(true, true); timeSelector::addOptions(true, true);
argList::noBanner(); argList::noBanner();
argList::noParallel(); argList::noParallel();
argList::noJobInfo();
argList::addBoolOption argList::addBoolOption
( (
"processor", "processor",

View File

@ -36,7 +36,6 @@
# file yet. Not supported by this script yet) # file yet. Not supported by this script yet)
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script=${0##*/}
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -52,6 +51,8 @@ TMPFILE=/tmp/${Script}$$.tmp
MACHDIR=$HOME/.OpenFOAM/${Script} MACHDIR=$HOME/.OpenFOAM/${Script}
DEFSTATEFILE=$HOME/.OpenFOAM/foamCheckJobs.out DEFSTATEFILE=$HOME/.OpenFOAM/foamCheckJobs.out
# The default is "~/.OpenFOAM/jobControl"
: ${FOAM_JOB_DIR:=$HOME/.OpenFOAM/jobControl}
if [ `uname -s` = Linux ] if [ `uname -s` = Linux ]
then then
@ -196,13 +197,6 @@ fi
#- Check a few things #- Check a few things
if [ ! "$FOAM_JOB_DIR" ]
then
echo "$Script : FOAM_JOB_DIR environment variable not set."
echo
exit 1
fi
if [ ! -d "$FOAM_JOB_DIR" ] if [ ! -d "$FOAM_JOB_DIR" ]
then then
echo "$Script : directory does not exist." echo "$Script : directory does not exist."

View File

@ -34,6 +34,8 @@ Script=${0##*/}
JOBSTRING='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n' JOBSTRING='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n'
DEFSTATEFILE=$HOME/.OpenFOAM/foamCheckJobs.out DEFSTATEFILE=$HOME/.OpenFOAM/foamCheckJobs.out
# The default is "~/.OpenFOAM/jobControl"
: ${FOAM_JOB_DIR:=$HOME/.OpenFOAM/jobControl}
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -120,12 +122,6 @@ fi
#- Check a few things #- Check a few things
if [ ! "$FOAM_JOB_DIR" ]
then
echo "$Script : FOAM_JOB_DIR environment variable not set."
echo
exit 1
fi
if [ ! -d "$FOAM_JOB_DIR" ] if [ ! -d "$FOAM_JOB_DIR" ]
then then
echo "$Script : directory does not exist." echo "$Script : directory does not exist."

View File

@ -25,8 +25,8 @@
# etc/bashrc # etc/bashrc
# #
# Description # Description
# Startup file for OpenFOAM # Set the environment for OpenFOAM when using a POSIX shell.
# Sourced from ~/.profile or ~/.bashrc # To be sourced manually or from the ~/.profile or ~/.bashrc files.
# Should be usable by any POSIX-compliant shell (eg, dash, ksh) # Should be usable by any POSIX-compliant shell (eg, dash, ksh)
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -25,7 +25,7 @@
# etc/config.csh/compiler # etc/config.csh/compiler
# #
# Description # Description
# Startup file for custom compiler versions for OpenFOAM # Setup file for custom compiler versions for OpenFOAM
# Sourced from OpenFOAM-<VERSION>/etc/config.csh/settings # Sourced from OpenFOAM-<VERSION>/etc/config.csh/settings
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -25,7 +25,7 @@
# etc/config.csh/settings # etc/config.csh/settings
# #
# Description # Description
# Startup file for OpenFOAM # Setup file for OpenFOAM
# Sourced from OpenFOAM-<VERSION>/etc/cshrc # Sourced from OpenFOAM-<VERSION>/etc/cshrc
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -137,8 +137,8 @@ endsw
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Location of the jobControl directory # Optional jobControl directory: unset is equivalent to ~/.OpenFOAM/jobControl
setenv FOAM_JOB_DIR $WM_PROJECT_INST_DIR/jobControl # setenv FOAM_JOB_DIR "$HOME/.OpenFOAM/jobControl"
# wmake configuration # wmake configuration
setenv WM_DIR $WM_PROJECT_DIR/wmake setenv WM_DIR $WM_PROJECT_DIR/wmake

View File

@ -25,7 +25,7 @@
# etc/config.sh/compiler # etc/config.sh/compiler
# #
# Description # Description
# Startup file for custom compiler versions for OpenFOAM # Setup file for custom compiler versions for OpenFOAM
# Sourced from OpenFOAM-<VERSION>/etc/config.sh/settings # Sourced from OpenFOAM-<VERSION>/etc/config.sh/settings
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -25,7 +25,7 @@
# etc/config.sh/settings # etc/config.sh/settings
# #
# Description # Description
# Startup file for OpenFOAM # Setup file for OpenFOAM
# Sourced from OpenFOAM-<VERSION>/etc/bashrc # Sourced from OpenFOAM-<VERSION>/etc/bashrc
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -140,8 +140,8 @@ esac
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Location of the jobControl directory # Optional jobControl directory: unset is equivalent to ~/.OpenFOAM/jobControl
export FOAM_JOB_DIR=$WM_PROJECT_INST_DIR/jobControl # export FOAM_JOB_DIR="$HOME/.OpenFOAM/jobControl"
# wmake configuration # wmake configuration
export WM_DIR=$WM_PROJECT_DIR/wmake export WM_DIR=$WM_PROJECT_DIR/wmake

View File

@ -25,8 +25,8 @@
# etc/cshrc # etc/cshrc
# #
# Description # Description
# Startup file for OpenFOAM # Set the environment for OpenFOAM when using a cshell.
# Sourced from ~/.login or ~/.cshrc # To be sourced manually or from the ~/.login or ~/.cshrc files.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,74 +28,14 @@ License
#include "clock.H" #include "clock.H"
#include "OFstream.H" #include "OFstream.H"
#include "Pstream.H" #include "Pstream.H"
#include "foamVersion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
bool Foam::JobInfo::writeJobInfo(Foam::debug::infoSwitch("writeJobInfo", 0)); bool Foam::JobInfo::writeJobInfo(Foam::debug::infoSwitch("writeJobInfo", 0));
Foam::JobInfo Foam::jobInfo; Foam::JobInfo Foam::jobInfo;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::JobInfo::JobInfo()
:
runningJobPath_(),
finishedJobPath_(),
cpuTime_()
{
name() = "JobInfo";
if (writeJobInfo && 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())
{
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);
}
}
constructed = true;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::JobInfo::~JobInfo()
{
if (writeJobInfo && constructed && Pstream::master())
{
mv(runningJobPath_, finishedJobPath_);
}
constructed = false;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::JobInfo::write(Ostream& os) const bool Foam::JobInfo::write(Ostream& os) const
{ {
@ -118,21 +58,6 @@ bool Foam::JobInfo::write(Ostream& os) const
} }
void Foam::JobInfo::write() const
{
if (writeJobInfo && Pstream::master())
{
if (!write(OFstream(runningJobPath_)()))
{
FatalErrorInFunction
<< "Failed to write to JobInfo file "
<< runningJobPath_
<< Foam::exit(FatalError);
}
}
}
void Foam::JobInfo::end(const word& terminationType) void Foam::JobInfo::end(const word& terminationType)
{ {
if (writeJobInfo && constructed && Pstream::master()) if (writeJobInfo && constructed && Pstream::master())
@ -146,14 +71,87 @@ void Foam::JobInfo::end(const word& terminationType)
add("termination", terminationType); add("termination", terminationType);
} }
rm(runningJobPath_); Foam::rm(runningDir_/jobFileName_);
write(OFstream(finishedJobPath_)()); write(OFstream(finishedDir_/jobFileName_)());
} }
constructed = false; constructed = false;
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::JobInfo::JobInfo()
:
jobFileName_(),
runningDir_(),
finishedDir_(),
cpuTime_()
{
name() = "JobInfo";
if (writeJobInfo && Pstream::master())
{
string jobDir = getEnv("FOAM_JOB_DIR");
if (jobDir.empty())
{
// Fallback: ~/.OpenFOAM/jobControl
jobDir = home()/WM_USER_RESOURCE_DIRNAME/"jobControl";
}
jobFileName_ = hostName() + '.' + Foam::name(pid());
runningDir_ = jobDir/"runningJobs";
finishedDir_ = jobDir/"finishedJobs";
if (!isDir(jobDir) && !mkDir(jobDir))
{
FatalErrorInFunction
<< "No JobInfo directory: FOAM_JOB_DIR=" << jobDir
<< Foam::exit(FatalError);
}
if (!isDir(runningDir_) && !mkDir(runningDir_))
{
FatalErrorInFunction
<< "No JobInfo directory: " << runningDir_
<< Foam::exit(FatalError);
}
if (!isDir(finishedDir_) && !mkDir(finishedDir_))
{
FatalErrorInFunction
<< "No JobInfo directory: " << finishedDir_
<< Foam::exit(FatalError);
}
}
constructed = true;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::JobInfo::~JobInfo()
{
signalEnd();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::JobInfo::write() const
{
if (writeJobInfo && constructed && Pstream::master())
{
const fileName output = runningDir_/jobFileName_;
if (!write(OFstream(output)()))
{
FatalErrorInFunction
<< "Failed to write to JobInfo file " << output
<< Foam::exit(FatalError);
}
}
}
void Foam::JobInfo::end() void Foam::JobInfo::end()
{ {
end("normal"); end("normal");
@ -176,9 +174,8 @@ void Foam::JobInfo::signalEnd() const
{ {
if (writeJobInfo && constructed && Pstream::master()) if (writeJobInfo && constructed && Pstream::master())
{ {
mv(runningJobPath_, finishedJobPath_); Foam::mv(runningDir_/jobFileName_, finishedDir_/jobFileName_);
} }
constructed = false; constructed = false;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,6 +31,8 @@ Description
- $FOAM_JOB_DIR/runningJobs - $FOAM_JOB_DIR/runningJobs
- $FOAM_JOB_DIR/finishedJobs - $FOAM_JOB_DIR/finishedJobs
If FOAM_JOB_DIR is unset, defaults to ~/.OpenFOAM/jobControl
SourceFiles SourceFiles
JobInfo.C JobInfo.C
@ -57,21 +59,28 @@ class JobInfo
public dictionary public dictionary
{ {
// Private data // Private data
fileName runningJobPath_;
fileName finishedJobPath_; //- The name of the job file
string jobFileName_;
fileName runningDir_;
fileName finishedDir_;
cpuTime cpuTime_; cpuTime cpuTime_;
// Private Member Functions // Private Member Functions
bool write(Ostream&) const; bool write(Ostream& os) const;
void end(const word& terminationType); void end(const word& terminationType);
public: public:
//- Global value for constructed job info
static bool constructed; static bool constructed;
//- Global value for writeJobInfo enabled
static bool writeJobInfo; static bool writeJobInfo;
// Constructors // Constructors
//- Construct null //- Construct null
@ -79,21 +88,25 @@ public:
//- Destructor //- Destructor
// Update job info and relocate the file from running to finished.
~JobInfo(); ~JobInfo();
// Member Functions // Member Functions
// Write //- Write the job info to its file in the runningJobs directory
void write() const; void write() const;
//- End with "termination=normal"
void end(); void end();
//- End with "termination=exit"
void exit(); void exit();
//- End with "termination=abort"
void abort(); void abort();
//- Update job info and relocate the file from running to finished.
void signalEnd() const; void signalEnd() const;
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -173,6 +173,12 @@ void Foam::argList::noFunctionObjects(bool addWithOption)
} }
void Foam::argList::noJobInfo()
{
JobInfo::writeJobInfo = false;
}
void Foam::argList::noParallel() void Foam::argList::noParallel()
{ {
removeOption("parallel"); removeOption("parallel");

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -352,6 +352,9 @@ public:
// optionally adding a 'withFunctionObjects' option instead // optionally adding a 'withFunctionObjects' option instead
static void noFunctionObjects(bool addWithOption = false); static void noFunctionObjects(bool addWithOption = false);
//- Suppress JobInfo, overriding controlDict setting
static void noJobInfo();
//- Remove the parallel options //- Remove the parallel options
static void noParallel(); static void noParallel();