MAIA bb96820c
Multiphysics at AIA
|
Class to create a create an output stream for a writable file, using either MPI I/O or a physical file. More...
#include <infoout.h>
Public Member Functions | |
InfoOutFile () | |
Default constructor creates (virtual) file that cannot yet be used. More... | |
InfoOutFile (const MString &filename, const MString &projectName, MInt fileType=0, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool rootOnlyHardwired=false) | |
Constructor creates InfoOut_mpiFileBuffer buffer and calls ostream constructor with reference to it. More... | |
~InfoOutFile () | |
Destructor closes the stream. More... | |
void | open (const MString &filename, const MString &projectName, MInt fileType=0, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool rootOnlyHardwired=false) |
Opens a file by passing the parameters to InfoOut_<xyz>FileBuffer::open(...). More... | |
void | close (MBool forceClose=false) |
Pass the close call to the respective internal buffer. More... | |
MBool | setRootOnly (MBool rootOnly=true) |
Sets interal state of whether only the root domain (rank 0) should write to file. More... | |
MInt | setMinFlushSize (MInt minFlushSize) |
Sets the minimum buffer length that has to be reached before the buffer is flushed. More... | |
Public Member Functions inherited from InfoOut | |
InfoOut () | |
virtual MBool | setRootOnly (MBool rootOnly=true)=0 |
MInt | addAttribute (std::pair< MString, MString >) |
Adds an attribute to the prefix of the XML string. More... | |
void | eraseAttribute (MInt) |
Erases an attribute from the prefix of the XML string. More... | |
void | modifyAttribute (MInt, std::pair< MString, MString >) |
Modifies an attribute of the prefix of the XML string. More... | |
Private Attributes | |
MInt | m_fileType |
File type that is opened. More... | |
MBool | m_isOpen |
Stores whether a file was already opened or not. More... | |
Additional Inherited Members | |
Protected Attributes inherited from InfoOut | |
InfoOut_buffer * | m_buffer = nullptr |
This class can be used to open a file on all processors (alternatively: only on a specified MPI communicator) and write to it using the normal C++ stream syntax (i.e. just like cout or cerr). Internally, it uses a InfoOut_mpiFileBuffer object as the internal buffer, and can thus hide all MPI-related commands from the user.
Alternatively, it is also possible to use regular physical files for each processor, and to write directly to it using a regular ofstream. This mode also allows for the setting that only process 0 within an MPI communicator opens a file to write to.
InfoOutFile::InfoOutFile | ( | ) |
When this constructor is used, open() needs to be called before the stream can be used.
Definition at line 930 of file infoout.cpp.
InfoOutFile::InfoOutFile | ( | const MString & | filename, |
const MString & | projectName, | ||
MInt | fileType = 0 , |
||
MPI_Comm | mpiComm = MPI_COMM_WORLD , |
||
MBool | rootOnlyHardwired = false |
||
) |
When this constructor is used, the stream is immediately ready to use. For information about the paramters, please have a look at InfoOut_mpiFileBuffer::open.
[in] | filename | Name of the file to open. |
[in] | mpiComm | MPI communicator for which to open the file. |
[in] | projectName | Projectname given. |
Definition at line 945 of file infoout.cpp.
InfoOutFile::~InfoOutFile | ( | ) |
Definition at line 956 of file infoout.cpp.
void InfoOutFile::close | ( | MBool | forceClose = false | ) |
All attempts to write to the stream after closing it will be discarded.
Definition at line 1011 of file infoout.cpp.
void InfoOutFile::open | ( | const MString & | filename, |
const MString & | projectName, | ||
MInt | fileType = 0 , |
||
MPI_Comm | mpiComm = MPI_COMM_WORLD , |
||
MBool | rootOnlyHardwired = false |
||
) |
The parameter fileType can be any of the constants defined in namespace MAIA_INFOOUT_FILETYPES. This method then creates a new internal buffer anbd passes along the parameters.
[in] | filename | Name of the file to open. |
[in] | fileType | Type of file that should be opened. Can be any of the constants defined in MAIA_INFOOUT_FILETYPES. |
[in] | mpiComm | MPI communicator for which to open the file. |
[in] | rootOnlyHardwired | If true, only rank 0 creates a file and writes to it. On all other processors, no file is opened and at each flushing of the buffer, the buffer content is discarded. This parameter makes only sense when using MAIA_INFOOUT_SIMPLE_FILE and is ignored otherwise. |
[in] | projectName | Name of the executed program. |
Definition at line 975 of file infoout.cpp.
Flushing the buffer means that the contents of the buffer in memory is written to the file. If the file stream was not opened yet, this method just returns 0 and does nothing else.
\params[in] minFlushSize Minimum buffer length.
Definition at line 1055 of file infoout.cpp.
\params[in] rootOnly If true, only rank 0 of the specified MPI communicator writes to file.
Implements InfoOut.
Definition at line 1043 of file infoout.cpp.