ENH: dummy fileOperation: placeholder for interfaces taking a reference
STYLE: align readOnProc/writeOnProc naming within masterUncollated
This commit is contained in:
parent
a34262966b
commit
d34dfbe0b7
3
applications/test/fileHandler-dummy/Make/files
Normal file
3
applications/test/fileHandler-dummy/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-fileHandler-dummy.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-fileHandler-dummy
|
2
applications/test/fileHandler-dummy/Make/options
Normal file
2
applications/test/fileHandler-dummy/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
79
applications/test/fileHandler-dummy/Test-fileHandler-dummy.C
Normal file
79
applications/test/fileHandler-dummy/Test-fileHandler-dummy.C
Normal file
@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-fileHandler-dummy
|
||||
|
||||
Description
|
||||
Simple test of dummy fileOperation
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "fileName.H"
|
||||
#include "fileOperation.H"
|
||||
#include "Switch.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noBanner();
|
||||
argList::noCheckProcessorDirectories();
|
||||
|
||||
argList::addBoolOption
|
||||
(
|
||||
"force",
|
||||
"Force use of dummy handler (and provoke NotImplemented)"
|
||||
);
|
||||
|
||||
#include "setRootCase.H"
|
||||
|
||||
const bool optForce = args.found("force");
|
||||
|
||||
const auto& dummy = fileOperation::null();
|
||||
|
||||
Info<< "default handler: " << fileHandler() << endl;
|
||||
Info<< "dummy handler: " << dummy() << endl;
|
||||
|
||||
Switch hasFile(Switch::INVALID);
|
||||
|
||||
if (optForce || (dummy && dummy().good()))
|
||||
{
|
||||
hasFile = dummy().isFile("foo");
|
||||
}
|
||||
|
||||
Info<< "check file: " << hasFile << endl;
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -22,6 +22,7 @@ $(fileOps)/fileOperation/fileOperationBroadcast.C
|
||||
$(fileOps)/fileOperation/fileOperationNew.C
|
||||
$(fileOps)/fileOperation/fileOperationRanks.C
|
||||
$(fileOps)/fileOperationInitialise/fileOperationInitialise.C
|
||||
$(fileOps)/dummyFileOperation/dummyFileOperation.C
|
||||
$(fileOps)/uncollatedFileOperation/uncollatedFileOperation.C
|
||||
$(fileOps)/masterUncollatedFileOperation/masterUncollatedFileOperation.C
|
||||
$(fileOps)/collatedFileOperation/collatedFileOperation.C
|
||||
|
@ -176,6 +176,7 @@ public:
|
||||
Class collatedFileOperationInitialise Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//! Internal class only
|
||||
class collatedFileOperationInitialise
|
||||
:
|
||||
public masterUncollatedFileOperationInitialise
|
||||
|
@ -0,0 +1,385 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dummyFileOperation.H"
|
||||
#include "dummyISstream.H"
|
||||
#include "Fstream.H"
|
||||
#include "objectRegistry.H"
|
||||
|
||||
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileOperations
|
||||
{
|
||||
defineTypeName(dummyFileOperation);
|
||||
|
||||
// No runtime selection
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileOperations::dummyFileOperation::dummyFileOperation
|
||||
(
|
||||
bool verbose
|
||||
)
|
||||
:
|
||||
fileOperation
|
||||
(
|
||||
// Use COMM_SELF for now, but COMM_NULL is probably more appropriate
|
||||
Tuple2<label, labelList>
|
||||
(
|
||||
UPstream::selfComm,
|
||||
fileOperation::getGlobalIORanks()
|
||||
)
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileOperations::dummyFileOperation::~dummyFileOperation()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Filesystem Operations * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::mkDir
|
||||
(
|
||||
const fileName& dir,
|
||||
mode_t mode
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::chMod
|
||||
(
|
||||
const fileName& fName,
|
||||
mode_t mode
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
mode_t Foam::fileOperations::dummyFileOperation::mode
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return mode_t(0);
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName::Type Foam::fileOperations::dummyFileOperation::type
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return fileName::Type::UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::exists
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool checkGzip,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::isDir
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::isFile
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool checkGzip,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
off_t Foam::fileOperations::dummyFileOperation::fileSize
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return off_t(0);
|
||||
}
|
||||
|
||||
|
||||
time_t Foam::fileOperations::dummyFileOperation::lastModified
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return time_t(0);
|
||||
}
|
||||
|
||||
|
||||
double Foam::fileOperations::dummyFileOperation::highResLastModified
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Foam::fileNameList Foam::fileOperations::dummyFileOperation::readDir
|
||||
(
|
||||
const fileName& dir,
|
||||
const fileName::Type type,
|
||||
const bool filtergz,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return fileNameList();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::cp
|
||||
(
|
||||
const fileName& src,
|
||||
const fileName& dst,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::ln
|
||||
(
|
||||
const fileName& src,
|
||||
const fileName& dst
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::mv
|
||||
(
|
||||
const fileName& src,
|
||||
const fileName& dst,
|
||||
const bool followLink
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::mvBak
|
||||
(
|
||||
const fileName& fName,
|
||||
const std::string& ext
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::rm
|
||||
(
|
||||
const fileName& fName
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::rmDir
|
||||
(
|
||||
const fileName& dir,
|
||||
const bool silent,
|
||||
const bool emptyOnly
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName Foam::fileOperations::dummyFileOperation::filePath
|
||||
(
|
||||
const bool checkGlobal,
|
||||
const IOobject& io,
|
||||
const word& typeName,
|
||||
const bool search
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return fileName();
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::fileOperations::dummyFileOperation::dirPath
|
||||
(
|
||||
const bool checkGlobal,
|
||||
const IOobject& io,
|
||||
const bool search
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return fileName();
|
||||
}
|
||||
|
||||
|
||||
Foam::fileNameList Foam::fileOperations::dummyFileOperation::readObjects
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const fileName& instance,
|
||||
const fileName& local,
|
||||
word& newInstance
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return fileNameList();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::readHeader
|
||||
(
|
||||
IOobject& io,
|
||||
const fileName& fName,
|
||||
const word& typeName
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
io.resetHeader();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::ISstream>
|
||||
Foam::fileOperations::dummyFileOperation::readStream
|
||||
(
|
||||
regIOobject& io,
|
||||
const fileName& fName,
|
||||
const word& typeName,
|
||||
const bool readOnProc
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<ISstream>(new dummyISstream());
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileOperations::dummyFileOperation::read
|
||||
(
|
||||
regIOobject& io,
|
||||
const bool masterOnly,
|
||||
const IOstreamOption::streamFormat format,
|
||||
const word& typeName
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::ISstream>
|
||||
Foam::fileOperations::dummyFileOperation::NewIFstream
|
||||
(
|
||||
const fileName& filePath
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<ISstream>(new dummyISstream());
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::OSstream>
|
||||
Foam::fileOperations::dummyFileOperation::NewOFstream
|
||||
(
|
||||
const fileName& pathName,
|
||||
IOstreamOption streamOpt,
|
||||
const bool writeOnProc
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<OSstream>(new OFstream(nullptr)); // ie, /dev/null
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::OSstream>
|
||||
Foam::fileOperations::dummyFileOperation::NewOFstream
|
||||
(
|
||||
IOstreamOption::atomicType atomic,
|
||||
const fileName& pathName,
|
||||
IOstreamOption streamOpt,
|
||||
const bool writeOnProc
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<OSstream>(new OFstream(nullptr)); // ie, /dev/null
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -0,0 +1,290 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::fileOperations::dummyFileOperation
|
||||
|
||||
Description
|
||||
Dummy fileOperation, to be used as a placeholder for interfaces
|
||||
taking a reference to a fileOperation.
|
||||
Will mostly behave like a no-op, but at the moment no guarantees
|
||||
of any particular behaviour other than good() returning false.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_fileOperations_dummyFileOperation_H
|
||||
#define Foam_fileOperations_dummyFileOperation_H
|
||||
|
||||
#include "fileOperation.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileOperations
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class dummyFileOperation Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class dummyFileOperation
|
||||
:
|
||||
public fileOperation
|
||||
{
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeNameNoDebug("dummy");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Default construct
|
||||
explicit dummyFileOperation(bool verbose = false);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~dummyFileOperation();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- This fileOperation is not really valid for anything.
|
||||
virtual bool good() const { return false; }
|
||||
|
||||
//- No managed communicator
|
||||
virtual void storeComm() const {}
|
||||
|
||||
|
||||
// OSSpecific equivalents
|
||||
|
||||
//- Make directory
|
||||
virtual bool mkDir(const fileName&, mode_t=0777) const;
|
||||
|
||||
//- Set the file mode
|
||||
virtual bool chMod(const fileName&, const mode_t) const;
|
||||
|
||||
//- Return the file mode
|
||||
virtual mode_t mode
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or SYMLINK
|
||||
virtual fileName::Type type
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist (as DIRECTORY or FILE) in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool exists
|
||||
(
|
||||
const fileName&,
|
||||
const bool checkGzip=true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist as a DIRECTORY in the file system?
|
||||
virtual bool isDir
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Does the name exist as a FILE in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
virtual bool isFile
|
||||
(
|
||||
const fileName&,
|
||||
const bool checkGzip=true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return size of file
|
||||
virtual off_t fileSize
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return time of last file modification
|
||||
virtual time_t lastModified
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return time of last file modification
|
||||
virtual double highResLastModified
|
||||
(
|
||||
const fileName&,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Read a directory and return the entries as a string list
|
||||
virtual fileNameList readDir
|
||||
(
|
||||
const fileName&,
|
||||
const fileName::Type=fileName::FILE,
|
||||
const bool filtergz=true,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Copy, recursively if necessary, the source to the destination
|
||||
virtual bool cp
|
||||
(
|
||||
const fileName& src,
|
||||
const fileName& dst,
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Create a softlink. dst should not exist. Returns true if
|
||||
// successful.
|
||||
virtual bool ln(const fileName& src, const fileName& dst) const;
|
||||
|
||||
//- Rename src to dst
|
||||
virtual bool mv
|
||||
(
|
||||
const fileName& src,
|
||||
const fileName& dst,
|
||||
const bool followLink = false
|
||||
) const;
|
||||
|
||||
//- Rename to a corresponding backup file
|
||||
// If the backup file already exists, attempt with
|
||||
// "01" .. "99" suffix
|
||||
virtual bool mvBak
|
||||
(
|
||||
const fileName&,
|
||||
const std::string& ext = "bak"
|
||||
) const;
|
||||
|
||||
//- Remove a file, returning true if successful otherwise false
|
||||
virtual bool rm(const fileName&) const;
|
||||
|
||||
//- Remove a directory and its contents
|
||||
// \param dir the directory to remove
|
||||
// \param silent do not report missing directory
|
||||
// \param emptyOnly only remove empty directories (recursive)
|
||||
virtual bool rmDir
|
||||
(
|
||||
const fileName& dir,
|
||||
const bool silent = false,
|
||||
const bool emptyOnly = false
|
||||
) const;
|
||||
|
||||
|
||||
// (reg)IOobject functionality
|
||||
|
||||
//- Search for an object. checkGlobal
|
||||
virtual fileName filePath
|
||||
(
|
||||
const bool checkGlobal,
|
||||
const IOobject& io,
|
||||
const word& typeName,
|
||||
const bool search
|
||||
) const;
|
||||
|
||||
//- Search for a directory. checkGlobal
|
||||
virtual fileName dirPath
|
||||
(
|
||||
const bool checkGlobal,
|
||||
const IOobject& io,
|
||||
const bool search
|
||||
) const;
|
||||
|
||||
//- Search directory for objects. Used in IOobjectList.
|
||||
virtual fileNameList readObjects
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const fileName& instance,
|
||||
const fileName& local,
|
||||
word& newInstance
|
||||
) const;
|
||||
|
||||
//- Read object header from supplied file
|
||||
virtual bool readHeader
|
||||
(
|
||||
IOobject&,
|
||||
const fileName&,
|
||||
const word& typeName
|
||||
) const;
|
||||
|
||||
//- Reads header for regIOobject and returns an ISstream
|
||||
//- to read the contents.
|
||||
virtual autoPtr<ISstream> readStream
|
||||
(
|
||||
regIOobject&,
|
||||
const fileName&,
|
||||
const word& typeName,
|
||||
const bool readOnProc = true
|
||||
) const;
|
||||
|
||||
//- Top-level read
|
||||
virtual bool read
|
||||
(
|
||||
regIOobject&,
|
||||
const bool masterOnly,
|
||||
const IOstreamOption::streamFormat format,
|
||||
const word& typeName
|
||||
) const;
|
||||
|
||||
//- Generate an ISstream that reads a file
|
||||
virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
|
||||
|
||||
//- Generate an OSstream that writes a file
|
||||
virtual autoPtr<OSstream> NewOFstream
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const bool writeOnProc = true
|
||||
) const;
|
||||
|
||||
//- Generate an OSstream that writes a file
|
||||
virtual autoPtr<OSstream> NewOFstream
|
||||
(
|
||||
IOstreamOption::atomicType,
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const bool writeOnProc = true
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileOperations
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
@ -143,6 +143,14 @@ public:
|
||||
typedef IntRange<int> procRangeType;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Static Data
|
||||
|
||||
//- Storage of the dummy file handler (demand-driven)
|
||||
static refPtr<fileOperation> dummyHandlerPtr_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Static Data
|
||||
@ -272,6 +280,9 @@ public:
|
||||
//- The currently active file handler. Avoid accessing directly
|
||||
static refPtr<fileOperation> fileHandlerPtr_;
|
||||
|
||||
//- Reference to a dummy file handler.
|
||||
static refPtr<fileOperation> null();
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -501,6 +512,10 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- True if the fileOperation can be considered valid.
|
||||
//- At the moment, primarily used to detect the dummy fileOperation.
|
||||
virtual bool good() const { return true; }
|
||||
|
||||
//- Transfer ownership of communicator to this fileOperation.
|
||||
//- Use with caution
|
||||
virtual void storeComm() const = 0;
|
||||
|
@ -26,15 +26,30 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fileOperation.H"
|
||||
#include "dummyFileOperation.H"
|
||||
#include "uncollatedFileOperation.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::refPtr<Foam::fileOperation> Foam::fileOperation::dummyHandlerPtr_;
|
||||
|
||||
Foam::refPtr<Foam::fileOperation> Foam::fileOperation::fileHandlerPtr_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::refPtr<Foam::fileOperation> Foam::fileOperation::null()
|
||||
{
|
||||
if (!dummyHandlerPtr_)
|
||||
{
|
||||
// verbose = false
|
||||
dummyHandlerPtr_.reset(new fileOperations::dummyFileOperation(false));
|
||||
}
|
||||
|
||||
return dummyHandlerPtr_;
|
||||
}
|
||||
|
||||
|
||||
const Foam::fileOperation& Foam::fileOperation::fileHandler()
|
||||
{
|
||||
if (!fileOperation::fileHandlerPtr_)
|
||||
|
@ -428,10 +428,12 @@ Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
|
||||
void Foam::fileOperations::masterUncollatedFileOperation::readAndSend
|
||||
(
|
||||
const fileName& filePath,
|
||||
const labelUList& procs,
|
||||
const labelUList& recvProcs,
|
||||
PstreamBuffers& pBufs
|
||||
)
|
||||
{
|
||||
if (recvProcs.empty()) return;
|
||||
|
||||
IFstream ifs(filePath, IOstreamOption::BINARY);
|
||||
|
||||
if (!ifs.good())
|
||||
@ -462,7 +464,7 @@ void Foam::fileOperations::masterUncollatedFileOperation::readAndSend
|
||||
std::istreambuf_iterator<char>()
|
||||
);
|
||||
|
||||
for (const label proci : procs)
|
||||
for (const label proci : recvProcs)
|
||||
{
|
||||
UOPstream os(proci, pBufs);
|
||||
os.write(buf.data(), buf.length());
|
||||
@ -483,7 +485,7 @@ void Foam::fileOperations::masterUncollatedFileOperation::readAndSend
|
||||
List<char> buf(static_cast<label>(count));
|
||||
ifs.stdStream().read(buf.data(), count);
|
||||
|
||||
for (const label proci : procs)
|
||||
for (const label proci : recvProcs)
|
||||
{
|
||||
UOPstream os(proci, pBufs);
|
||||
os.write(buf.cdata(), count);
|
||||
@ -505,37 +507,35 @@ Foam::fileOperations::masterUncollatedFileOperation::read
|
||||
IOobject& io,
|
||||
const label comm,
|
||||
const bool uniform, // on comms master only
|
||||
const fileNameList& filePaths, // on comms master only
|
||||
const boolList& procValid // on comms master and sub-ranks
|
||||
const fileNameList& filePaths, // on comms master and sub-ranks
|
||||
const boolUList& readOnProcs // on comms master and sub-ranks
|
||||
)
|
||||
{
|
||||
autoPtr<ISstream> isPtr;
|
||||
|
||||
// const bool uniform = fileOperation::uniformFile(filePaths);
|
||||
|
||||
PstreamBuffers pBufs(comm, UPstream::commsTypes::nonBlocking);
|
||||
|
||||
if (UPstream::master(comm))
|
||||
{
|
||||
if (uniform)
|
||||
{
|
||||
if (procValid[0])
|
||||
if (readOnProcs[0])
|
||||
{
|
||||
if (filePaths[0].empty())
|
||||
{
|
||||
FatalIOErrorInFunction(filePaths[0])
|
||||
<< "cannot find file " << io.objectPath()
|
||||
<< "Cannot find file " << io.objectPath()
|
||||
<< " fileHandler : comm:" << comm
|
||||
<< " ioRanks:" << UPstream::procID(comm)
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
DynamicList<label> validProcs(Pstream::nProcs(comm));
|
||||
for (const int proci : Pstream::allProcs(comm))
|
||||
DynamicList<label> recvProcs(UPstream::nProcs(comm));
|
||||
for (const int proci : UPstream::allProcs(comm))
|
||||
{
|
||||
if (procValid[proci])
|
||||
if (readOnProcs[proci])
|
||||
{
|
||||
validProcs.append(proci);
|
||||
recvProcs.push_back(proci);
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,20 +545,20 @@ Foam::fileOperations::masterUncollatedFileOperation::read
|
||||
{
|
||||
Pout<< "masterUncollatedFileOperation::readStream :"
|
||||
<< " For uniform file " << filePaths[0]
|
||||
<< " sending to " << validProcs
|
||||
<< " sending to " << recvProcs
|
||||
<< " in comm:" << comm << endl;
|
||||
}
|
||||
readAndSend(filePaths[0], validProcs, pBufs);
|
||||
readAndSend(filePaths[0], recvProcs, pBufs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (procValid[0])
|
||||
if (readOnProcs[0])
|
||||
{
|
||||
if (filePaths[0].empty())
|
||||
{
|
||||
FatalIOErrorInFunction(filePaths[0])
|
||||
<< "cannot find file " << io.objectPath()
|
||||
<< "Cannot find file " << io.objectPath()
|
||||
<< " fileHandler : comm:" << comm
|
||||
<< " ioRanks:" << UPstream::procID(comm)
|
||||
<< exit(FatalIOError);
|
||||
@ -580,7 +580,7 @@ Foam::fileOperations::masterUncollatedFileOperation::read
|
||||
}
|
||||
|
||||
// Read sub-rank files
|
||||
for (const int proci : Pstream::subProcs(comm))
|
||||
for (const int proci : UPstream::subProcs(comm))
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
@ -591,7 +591,7 @@ Foam::fileOperations::masterUncollatedFileOperation::read
|
||||
|
||||
const fileName& fPath = filePaths[proci];
|
||||
|
||||
if (procValid[proci] && !fPath.empty())
|
||||
if (readOnProcs[proci] && !fPath.empty())
|
||||
{
|
||||
// Note: handle compression ourselves since size cannot
|
||||
// be determined without actually uncompressing
|
||||
@ -609,14 +609,14 @@ Foam::fileOperations::masterUncollatedFileOperation::read
|
||||
|
||||
if (!isPtr)
|
||||
{
|
||||
if (procValid[Pstream::myProcNo(comm)])
|
||||
if (readOnProcs[UPstream::myProcNo(comm)])
|
||||
{
|
||||
// This processor needs to return something
|
||||
List<char> buf(pBufs.recvDataCount(Pstream::masterNo()));
|
||||
List<char> buf(pBufs.recvDataCount(UPstream::masterNo()));
|
||||
|
||||
if (!buf.empty())
|
||||
{
|
||||
UIPstream is(Pstream::masterNo(), pBufs);
|
||||
UIPstream is(UPstream::masterNo(), pBufs);
|
||||
is.read(buf.data(), buf.size());
|
||||
}
|
||||
|
||||
@ -633,7 +633,7 @@ Foam::fileOperations::masterUncollatedFileOperation::read
|
||||
isPtr.reset(new IListStream(std::move(buf)));
|
||||
|
||||
// With the proper file name
|
||||
isPtr->name() = filePaths[Pstream::myProcNo(comm)];
|
||||
isPtr->name() = filePaths[UPstream::myProcNo(comm)];
|
||||
|
||||
if (!io.readHeader(*isPtr))
|
||||
{
|
||||
@ -1971,7 +1971,7 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
|
||||
splitProcessorPath(fName, path, procDir, local, group, nProcs);
|
||||
|
||||
|
||||
if (!Pstream::parRun())
|
||||
if (!UPstream::parRun())
|
||||
{
|
||||
// Analyse the objectpath to find out the processor we're trying
|
||||
// to access
|
||||
@ -2078,16 +2078,16 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
|
||||
{
|
||||
// Use worldComm. Note: should not really need to gather filePaths
|
||||
// since we enforce sending from master anyway ...
|
||||
fileNameList filePaths(Pstream::nProcs(UPstream::worldComm));
|
||||
filePaths[Pstream::myProcNo(UPstream::worldComm)] = fName;
|
||||
fileNameList filePaths(UPstream::nProcs(UPstream::worldComm));
|
||||
filePaths[UPstream::myProcNo(UPstream::worldComm)] = fName;
|
||||
Pstream::gatherList
|
||||
(
|
||||
filePaths,
|
||||
Pstream::msgType(),
|
||||
UPstream::msgType(),
|
||||
UPstream::worldComm
|
||||
);
|
||||
|
||||
boolList procValid
|
||||
boolList readOnProcs
|
||||
(
|
||||
UPstream::listGatherValues<bool>
|
||||
(
|
||||
@ -2096,30 +2096,40 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
|
||||
)
|
||||
);
|
||||
// NB: local proc validity information required on sub-ranks too!
|
||||
procValid.resize(Pstream::nProcs(UPstream::worldComm));
|
||||
procValid[Pstream::myProcNo(UPstream::worldComm)] = readOnProc;
|
||||
readOnProcs.resize(UPstream::nProcs(UPstream::worldComm));
|
||||
readOnProcs[UPstream::myProcNo(UPstream::worldComm)] = readOnProc;
|
||||
|
||||
return read(io, UPstream::worldComm, true, filePaths, procValid);
|
||||
// Uniform in local comm
|
||||
return read(io, UPstream::worldComm, true, filePaths, readOnProcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use local communicator
|
||||
fileNameList filePaths(Pstream::nProcs(comm_));
|
||||
filePaths[Pstream::myProcNo(comm_)] = fName;
|
||||
Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
|
||||
|
||||
boolList procValid
|
||||
fileNameList filePaths(UPstream::nProcs(comm_));
|
||||
filePaths[UPstream::myProcNo(comm_)] = fName;
|
||||
Pstream::gatherList
|
||||
(
|
||||
UPstream::listGatherValues<bool>(readOnProc, comm_)
|
||||
filePaths,
|
||||
UPstream::msgType(),
|
||||
comm_
|
||||
);
|
||||
|
||||
boolList readOnProcs
|
||||
(
|
||||
UPstream::listGatherValues<bool>
|
||||
(
|
||||
readOnProc,
|
||||
comm_
|
||||
)
|
||||
);
|
||||
// NB: local proc validity information required on sub-ranks too!
|
||||
procValid.resize(Pstream::nProcs(comm_));
|
||||
procValid[Pstream::myProcNo(comm_)] = readOnProc;
|
||||
readOnProcs.resize(UPstream::nProcs(comm_));
|
||||
readOnProcs[UPstream::myProcNo(comm_)] = readOnProc;
|
||||
|
||||
// Uniform in local comm
|
||||
const bool uniform = fileOperation::uniformFile(filePaths);
|
||||
|
||||
return read(io, comm_, uniform, filePaths, procValid);
|
||||
return read(io, comm_, uniform, filePaths, readOnProcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -454,7 +454,7 @@ protected:
|
||||
static void readAndSend
|
||||
(
|
||||
const fileName& filePath,
|
||||
const labelUList& procs,
|
||||
const labelUList& recvProcs,
|
||||
PstreamBuffers& pBufs
|
||||
);
|
||||
|
||||
@ -464,8 +464,8 @@ protected:
|
||||
IOobject& io,
|
||||
const label comm,
|
||||
const bool uniform, // on comms master only
|
||||
const fileNameList& filePaths, // on comms master only
|
||||
const boolList& procValid // on comms master only
|
||||
const fileNameList& filePaths, // on comms master and sub-ranks
|
||||
const boolUList& readOnProcs // on comms master and sub-ranks
|
||||
);
|
||||
|
||||
//- Helper: check IO for local existence. Like filePathInfo but
|
||||
@ -791,6 +791,7 @@ public:
|
||||
Class masterUncollatedFileOperationInitialise Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//! Internal class only
|
||||
class masterUncollatedFileOperationInitialise
|
||||
:
|
||||
public unthreadedInitialise
|
||||
|
@ -98,6 +98,7 @@ public:
|
||||
Class hostUncollatedFileOperationInitialise Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//! Internal class only
|
||||
class hostUncollatedFileOperationInitialise
|
||||
:
|
||||
public masterUncollatedFileOperationInitialise
|
||||
|
@ -614,10 +614,10 @@ Foam::fileOperations::uncollatedFileOperation::readStream
|
||||
regIOobject& io,
|
||||
const fileName& fName,
|
||||
const word& typeName,
|
||||
const bool writeOnProc
|
||||
const bool readOnProc
|
||||
) const
|
||||
{
|
||||
if (!writeOnProc)
|
||||
if (!readOnProc)
|
||||
{
|
||||
return autoPtr<ISstream>(new dummyISstream());
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ public:
|
||||
regIOobject&,
|
||||
const fileName&,
|
||||
const word& typeName,
|
||||
const bool procValid = true
|
||||
const bool readOnProc = true
|
||||
) const;
|
||||
|
||||
//- Top-level read
|
||||
|
Loading…
Reference in New Issue
Block a user