36 #undef Foam_UPstream_largeCountFile 38 #if (MPI_VERSION >= 4) 39 #define Foam_UPstream_largeCountFile 43 #ifdef Foam_UPstream_largeCountFile 44 #define Foam_mpiCall(Function) Function##_c 46 #define Foam_mpiCall(Function) Function 55 inline 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" 150 return (states::READ == state_);
156 return (states::ATOMIC_WRITE == state_);
162 return (states::ATOMIC_WRITE == state_ || states::WRITE == state_);
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(),
276 bool Foam::UPstream::File::open_read
278 const int communicator,
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;
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)
368 bool ok =
io.readHeader(headerDict, is);
381 return (MPI_SUCCESS == returnCode);
390 const int communicator,
400 <<
"Previous use of file handler did not call close()" <<
nl 401 <<
" FIX YOUR CODE!!" <<
endl;
406 file_->name() = pathname;
409 const bool atomic = (IOstreamOption::atomicType::ATOMIC == atomicType);
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);
bool checkReadable(const char *what) const
Assert is_read() or FatalError.
bool is_write() const noexcept
void size(const label n)
Older name for setAddressableSize.
bool write_data(const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write [non-collective] : write data.
static bool supported()
True if MPI/IO appears to be supported.
A class for handling file names.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
bool set_size(std::streamsize num_bytes)
Set the (output) file size [collective].
errorManipArg< error, int > exit(error &err, const int errNo=1)
An opaque wrapper for MPI_File methods without any <mpi.h> header dependency.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool is_open() const noexcept
bool is_atomic() const noexcept
constexpr char nl
The newline '\n' character (0x0a)
bool write_data_all(const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_all [collective] : write data.
static const fileName null
An empty fileName.
T * data() noexcept
Return pointer to the underlying array serving as data storage.
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
static int myProcNo(label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
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 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.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
atomicType
Atomic operations (output)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
const MPI_File & handle() const noexcept
const fileName & name() const
The name of the open stream.
int state(states val) noexcept
#define FOAM_UNLIKELY(cond)
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
errorManip< error > abort(error &err)
int rank() const noexcept
Get the associated rank.
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...
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
dataTypes
Mapping of some fundamental and aggregate types to MPI data types.
bool checkWritable(const char *what) const
Assert is_write() or 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.
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.
~File()
Destructor. Non-default in header (incomplete types)
bool is_read() const noexcept
void resize_nocopy(const label len)
Alter addressable list size, allocating new space if required without necessarily recovering old cont...
bool close()
MPI_File_close [collective].
bool master() const noexcept
Is rank 0 ? (master rank)
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
Inter-processor communications stream.
const fileName & name() const noexcept
bool is_open() const
True if allocated and open has been called.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.