36#undef Foam_UPstream_largeCountFile
39#define Foam_UPstream_largeCountFile
43#ifdef Foam_UPstream_largeCountFile
44#define Foam_mpiCall(Function) Function##_c
46#define Foam_mpiCall(Function) Function
55inline bool checkCount(std::streamsize count,
const char* what)
57 #ifndef Foam_UPstream_largeCountFile
62 <<
"Write size " << label(count)
63 <<
" exceeds INT_MAX bytes for '" << what <<
"'\n"
139 void rank(
int val)
noexcept { rank_ = val; }
171 <<
"File handler not open for reading '" << what <<
"'\n"
172 <<
"name: " <<
name() <<
nl
185 <<
"File handler not open for writing'" << what <<
"'\n"
186 <<
"name: " <<
name() <<
nl
220 <<
"Exited scope without close()" <<
nl
221 <<
" FIX YOUR CODE!!" <<
endl;
238 return bool(file_ && file_->is_open());
247 <<
"Called without an open file handler !" <<
endl;
251 MPI_File_close(&(file_->handle()));
254 const fileName& pathname = file_->
name();
256 if (file_->master() && file_->is_atomic() && !pathname.empty())
260 (pathname +
"~tmp~").c_str(),
276bool Foam::UPstream::File::open_read
278 const int communicator,
279 const fileName& pathname
287 <<
"Previous use of file handler did not call close()" <<
nl
288 <<
" FIX YOUR CODE!!" <<
endl;
293 file_->name() = pathname;
296 int returnCode = MPI_File_open
308 <<
"Error encounted in MPI_File_open() : "
316 file_->name() = pathname;
327bool Foam::UPstream::File::get_header(DynamicList<char>& content)
329 std::streamsize headerSize(4096);
332 file_->checkReadable(
"MPI_File_read_at");
336 std::streamsize size = std::streamsize(fileLen);
337 if (headerSize > size)
362 if (MPI_SUCCESS == returnCode)
364 ISpanStream is(content);
368 bool ok =
io.readHeader(headerDict, is);
381 return (MPI_SUCCESS == returnCode);
390 const int communicator,
391 const fileName& pathname,
400 <<
"Previous use of file handler did not call close()" <<
nl
401 <<
" FIX YOUR CODE!!" <<
endl;
406 file_->name() = pathname;
416 const fileName pathname_gz(pathname +
".gz");
417 const fileName pathname_tmp(pathname +
"~tmp~");
420 const auto& target = (atomic ? pathname_tmp : pathname);
442 int returnCode = MPI_File_open
446 (MPI_MODE_CREATE | MPI_MODE_WRONLY),
454 <<
"Error encounted in MPI_File_open() : "
462 file_->name() = pathname;
474 <<
"Called without an open file handler !" <<
endl;
478 int returnCode = MPI_File_set_size(file_->handle(), num_bytes);
480 return (MPI_SUCCESS == returnCode);
489 std::streamsize count,
496 file_->checkWritable(
"MPI_File_write");
497 checkCount(count,
"MPI_File_write");
508 return (MPI_SUCCESS == returnCode);
514 std::streamsize offset,
516 std::streamsize count,
523 file_->checkWritable(
"MPI_File_write_at");
524 checkCount(count,
"MPI_File_write_at");
536 return (MPI_SUCCESS == returnCode);
545 std::streamsize count,
552 file_->checkWritable(
"MPI_File_write_all");
553 checkCount(count,
"MPI_File_write_all");
564 return (MPI_SUCCESS == returnCode);
570 std::streamsize offset,
572 std::streamsize count,
579 file_->checkWritable(
"MPI_File_write_at_all");
580 checkCount(count,
"MPI_File_write_at_all");
592 return (MPI_SUCCESS == returnCode);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void resize_nocopy(const label len)
Alter addressable list size, allocating new space if required without necessarily recovering old cont...
atomicType
Atomic operations (output).
T * data() noexcept
Return pointer to the underlying array serving as data storage.
void size(const label n)
Older name for setAddressableSize.
bool checkReadable(const char *what) const
Assert is_read() or FatalError.
void rank(int val) noexcept
Set the associated rank.
MPI_File & handle() noexcept
bool is_write() const noexcept
bool is_open() const noexcept
bool is_read() const noexcept
bool master() const noexcept
Is rank 0 ? (master rank).
fileName & name() noexcept
bool checkWritable(const char *what) const
Assert is_write() or FatalError.
const fileName & name() const noexcept
int state(states val) noexcept
int rank() const noexcept
Get the associated rank.
bool is_atomic() const noexcept
const MPI_File & handle() const noexcept
~File()
Destructor. Non-default in header (incomplete types).
bool is_open() const
True if allocated and open has been called.
bool open_write(const int communicator, const fileName &pathname, IOstreamOption::atomicType=IOstreamOption::NON_ATOMIC)
MPI_File_open [collective] : open file in write-only mode, no-append.
bool write_data_at_all(std::streamsize offset, const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_at_all [collective] : write data at specified offset.
bool close()
MPI_File_close [collective].
File(const File &&)=delete
No copy construct.
const fileName & name() const
The name of the open stream.
static bool supported()
True if MPI/IO appears to be supported.
bool set_size(std::streamsize num_bytes)
Set the (output) file size [collective].
bool write_data_at(std::streamsize offset, const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_at [non-collective] : write data at specified offset.
bool write_data_all(const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_all [collective] : write data.
bool write_data(const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write [non-collective] : write data.
Inter-processor communications stream.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
UPstream(const commsTypes commsType) noexcept
Construct for given communication type.
dataTypes
Mapping of some fundamental and aggregate types to MPI data types.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
A class for handling file names.
@ SYMLINK
A symbolic link.
static const fileName null
An empty fileName.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
#define Foam_mpiCall(Function)
MPI_Datatype getDataType(UPstream::dataTypes id)
Lookup of dataTypes enumeration as an MPI_Datatype.
DynamicList< MPI_Comm > MPICommunicators_
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define FOAM_UNLIKELY(cond)