ENH: timeActivatedFileUpdate: avoid copying on master; simplified logic; Fixes #420.

This commit is contained in:
mattijs
2017-04-06 14:45:16 +01:00
parent 2da2970c7c
commit 498fa94cb3
7 changed files with 39 additions and 10 deletions

View File

@ -468,6 +468,7 @@ Foam::Time::Time
( (
args.parRunControl().parRun(), args.parRunControl().parRun(),
args.rootPath(), args.rootPath(),
args.distributed(),
args.globalCaseName(), args.globalCaseName(),
args.caseName(), args.caseName(),
systemName, systemName,

View File

@ -70,6 +70,7 @@ Foam::TimePaths::TimePaths
: :
processorCase_(false), processorCase_(false),
rootPath_(rootPath), rootPath_(rootPath),
distributed_(false),
globalCaseName_(caseName), globalCaseName_(caseName),
case_(caseName), case_(caseName),
system_(systemName), system_(systemName),
@ -84,6 +85,7 @@ Foam::TimePaths::TimePaths
( (
const bool processorCase, const bool processorCase,
const fileName& rootPath, const fileName& rootPath,
const bool distributed,
const fileName& globalCaseName, const fileName& globalCaseName,
const fileName& caseName, const fileName& caseName,
const word& systemName, const word& systemName,
@ -92,6 +94,7 @@ Foam::TimePaths::TimePaths
: :
processorCase_(processorCase), processorCase_(processorCase),
rootPath_(rootPath), rootPath_(rootPath),
distributed_(distributed),
globalCaseName_(globalCaseName), globalCaseName_(globalCaseName),
case_(caseName), case_(caseName),
system_(systemName), system_(systemName),

View File

@ -53,6 +53,7 @@ class TimePaths
bool processorCase_; bool processorCase_;
const fileName rootPath_; const fileName rootPath_;
bool distributed_;
fileName globalCaseName_; fileName globalCaseName_;
fileName case_; fileName case_;
const word system_; const word system_;
@ -84,6 +85,7 @@ public:
( (
const bool processorCase, const bool processorCase,
const fileName& rootPath, const fileName& rootPath,
const bool distributed,
const fileName& globalCaseName, const fileName& globalCaseName,
const fileName& caseName, const fileName& caseName,
const word& systemName, const word& systemName,
@ -139,6 +141,13 @@ public:
return constant_; return constant_;
} }
//- Is case running with parallel distributed directories
// (i.e. not NFS mounted)
bool distributed() const
{
return distributed_;
}
//- Return constant name for the case //- Return constant name for the case
// which for parallel runs returns ../constant() // which for parallel runs returns ../constant()
fileName caseConstant() const; fileName caseConstant() const;

View File

@ -429,7 +429,8 @@ Foam::argList::argList
) )
: :
args_(argc), args_(argc),
options_(argc) options_(argc),
distributed_(false)
{ {
// Check if this run is a parallel run by searching for any parallel option // Check if this run is a parallel run by searching for any parallel option
// If found call runPar which might filter argv // If found call runPar which might filter argv
@ -669,6 +670,7 @@ void Foam::argList::parse
label dictNProcs = -1; label dictNProcs = -1;
if (options_.found("roots")) if (options_.found("roots"))
{ {
distributed_ = true;
source = "-roots"; source = "-roots";
IStringStream is(options_["roots"]); IStringStream is(options_["roots"]);
roots = readList<fileName>(is); roots = readList<fileName>(is);
@ -700,7 +702,7 @@ void Foam::argList::parse
decompDict.lookup("numberOfSubdomains") decompDict.lookup("numberOfSubdomains")
); );
if (decompDict.lookupOrDefault("distributed", false)) if (decompDict.lookupOrDefault("distributed", distributed_))
{ {
decompDict.lookup("roots") >> roots; decompDict.lookup("roots") >> roots;
} }
@ -771,7 +773,7 @@ void Foam::argList::parse
options_.set("case", roots[slave-1]/globalCase_); options_.set("case", roots[slave-1]/globalCase_);
OPstream toSlave(Pstream::scheduled, slave); OPstream toSlave(Pstream::scheduled, slave);
toSlave << args_ << options_; toSlave << args_ << options_ << roots.size();
} }
options_.erase("case"); options_.erase("case");
@ -818,7 +820,7 @@ void Foam::argList::parse
) )
{ {
OPstream toSlave(Pstream::scheduled, slave); OPstream toSlave(Pstream::scheduled, slave);
toSlave << args_ << options_; toSlave << args_ << options_ << roots.size();
} }
} }
} }
@ -826,7 +828,7 @@ void Foam::argList::parse
{ {
// Collect the master's argument list // Collect the master's argument list
IPstream fromMaster(Pstream::scheduled, Pstream::masterNo()); IPstream fromMaster(Pstream::scheduled, Pstream::masterNo());
fromMaster >> args_ >> options_; fromMaster >> args_ >> options_ >> distributed_;
// Establish rootPath_/globalCase_/case_ for slave // Establish rootPath_/globalCase_/case_ for slave
getRootCase(); getRootCase();

View File

@ -109,6 +109,7 @@ class argList
word executable_; word executable_;
fileName rootPath_; fileName rootPath_;
bool distributed_;
fileName globalCase_; fileName globalCase_;
fileName case_; fileName case_;
string argListStr_; string argListStr_;
@ -221,6 +222,10 @@ public:
//- Return root path //- Return root path
inline const fileName& rootPath() const; inline const fileName& rootPath() const;
//- Return distributed flag (i.e. are rootPaths different on
// different machines)
inline bool distributed() const;
//- Return case name (parallel run) or global case (serial run) //- Return case name (parallel run) or global case (serial run)
inline const fileName& caseName() const; inline const fileName& caseName() 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-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 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.
@ -39,6 +39,12 @@ inline const Foam::fileName& Foam::argList::rootPath() const
} }
inline bool Foam::argList::distributed() const
{
return distributed_;
}
inline const Foam::fileName& Foam::argList::caseName() const inline const Foam::fileName& Foam::argList::caseName() const
{ {
return case_; return case_;

View File

@ -67,11 +67,14 @@ void Foam::functionObjects::timeActivatedFileUpdate::updateFile()
Log << nl << type() << ": copying file" << nl << timeVsFile_[i].second() Log << nl << type() << ": copying file" << nl << timeVsFile_[i].second()
<< nl << "to:" << nl << fileToUpdate_ << nl << endl; << nl << "to:" << nl << fileToUpdate_ << nl << endl;
if (Pstream::master() || time_.distributed())
{
// Slaves do not copy if running non-distributed
fileName destFile(fileToUpdate_ + Foam::name(pid())); fileName destFile(fileToUpdate_ + Foam::name(pid()));
cp(timeVsFile_[i].second(), destFile); cp(timeVsFile_[i].second(), destFile);
mv(destFile, fileToUpdate_); mv(destFile, fileToUpdate_);
}
lastIndex_ = i; lastIndex_ = i;
modified_ = true; modified_ = true;
} }
} }