MAIA bb96820c
Multiphysics at AIA
|
Customized buffer to facilitate of a regular physical file for each processor within an MPI communicator. More...
#include <infoout.h>
Public Member Functions | |
InfoOut_simpleFileBuffer () | |
Generic constructor is used when no information is provided during declaration. More... | |
InfoOut_simpleFileBuffer (const MString &filename, const MString &projectName, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool rootOnlyHardwired=false) | |
This constructor yields a new instance that can immediately be used to write messages to a regular file. More... | |
~InfoOut_simpleFileBuffer () | |
Destructor calls close() to close the file. More... | |
void | open (const MString &filename, const MString &projectName, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool rootOnlyHardwired=false) |
Initialization of the file I/O environment. More... | |
void | close (MBool forceClose=false) |
Closes the file. More... | |
Public Member Functions inherited from InfoOut_buffer | |
InfoOut_buffer () | |
Generic constructor is used when no information is provided during declaration. More... | |
virtual MBool | setRootOnly (MBool rootOnly=true) |
Sets interal state of whether only the root domain (rank 0) should write to file. More... | |
virtual MInt | setMinFlushSize (MInt minFlushSize) |
Sets the minimum buffer length that has to be reached before the buffer is flushed. More... | |
Protected Member Functions | |
virtual MInt | sync () |
Flushes the buffer by writing the contents to the file. More... | |
virtual void | flushBuffer () |
Flushes the buffer by writing the contents to the file. More... | |
Protected Member Functions inherited from InfoOut_buffer | |
virtual MString | encodeXml (const std::string &str) |
Parses the string input and returns the string with XML entities escaped. More... | |
virtual MString | getXmlHeader () |
Return an XML header that should written at the beginning of each log file. More... | |
virtual MString | getXmlFooter () |
Return an XML footer that should written at the end of each log file. More... | |
virtual void | createPrefixMessage () |
Creates an XML prefix using the domain id that is prepended to each message. More... | |
virtual void | createSuffixMessage () |
Creates an XML suffix that is appended to each message. More... | |
virtual void | flushBuffer ()=0 |
Private Attributes | |
MBool | m_isOpen |
Stores whether the file(s) were already opened. More... | |
MBool | m_rootOnlyHardwired |
If true, only domain 0 opens and uses a file. More... | |
MString | m_filename |
Filename on disk. More... | |
std::ofstream | m_file |
File stream tied to physical file on disk. More... | |
MPI_Comm | m_mpiComm |
MPI communicator group. More... | |
Additional Inherited Members | |
Protected Attributes inherited from InfoOut_buffer | |
MBool | m_rootOnly |
Stores whether only the root domain writes a log file. More... | |
MInt | m_domainId |
Contains the MPI rank (= domain id) of this process. More... | |
MInt | m_noDomains |
Contains the MPI rank count (= number of domains) More... | |
MInt | m_minFlushSize |
Minimum length of the internal buffer before flushing. More... | |
MString | m_prefixMessage |
Stores the prefix that is prepended to each output. More... | |
MString | m_suffixMessage |
Stores the suffix that is apended to each output. More... | |
std::ostringstream | m_tmpBuffer |
Temporary buffer to hold string until flushing. More... | |
MString | m_projectName |
Name of the current Project. More... | |
std::vector< std::pair< MString, MString > > | m_prefixAttributes |
Static Protected Attributes inherited from InfoOut_buffer | |
static const MInt | m_fileFormatVersion = 1 |
This class can be used as a regular string buffer, as it inherits from stringbuf. On flushing the buffer, the contents of the buffer are written to a file using an ofstream. This is mainly for cases where logging speed is crucial, as the implementation is very lightweight and since for each process an individual file is maintained. There is an option to use this buffer but to create only one file for the MPI root domain (see m_rootOnlyHardwired).
InfoOut_simpleFileBuffer::InfoOut_simpleFileBuffer | ( | ) |
Definition at line 331 of file infoout.cpp.
InfoOut_simpleFileBuffer::InfoOut_simpleFileBuffer | ( | const MString & | filename, |
const MString & | projectName, | ||
MPI_Comm | mpiComm = MPI_COMM_WORLD , |
||
MBool | rootOnlyHardwired = false |
||
) |
Internally, this constructor just passes the parameters to open() (see open() for more details).
[in] | filename | Filename that should be used for the file. |
[in] | mpiComm | MPI communicator which is used to determine rank/domain information. |
[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. |
[in] | projectName | Projectname that should be used for the executed program. |
Definition at line 348 of file infoout.cpp.
InfoOut_simpleFileBuffer::~InfoOut_simpleFileBuffer | ( | ) |
Definition at line 359 of file infoout.cpp.
void InfoOut_simpleFileBuffer::close | ( | MBool | forceClose = false | ) |
Any subsequent write statements to the file stream are discarded after this method is called. After close() is called, an XML footer is written to the file. Then the file is closed.
Definition at line 424 of file infoout.cpp.
|
inlineprotectedvirtual |
Sync is called automatically when an "endl" is sent to the stream. At first the buffer content is wrapped in the prefix and suffix messages, then the entire string is written to the file. Finally, the internal buffers are reset.
Implements InfoOut_buffer.
Definition at line 487 of file infoout.cpp.
void InfoOut_simpleFileBuffer::open | ( | const MString & | filename, |
const MString & | projectName, | ||
MPI_Comm | mpiComm = MPI_COMM_WORLD , |
||
MBool | rootOnlyHardwired = false |
||
) |
After a successful call to this method the file stream is ready to use. Any previous information written to the buffer is lost when open is called. This function creates a new file as specified in filename (deleting any existing files with the same name), and creates the XML prefixes and suffixes used for each message. It also writes the necessary XML header information to the file.
[in] | filename | Filename that should be used for the file. |
[in] | mpiComm | MPI communicator which is used to determine rank/domain information. |
[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. |
[in] | projectName | Projectname that should be used for the executed program. |
Definition at line 376 of file infoout.cpp.
|
protectedvirtual |
Sync is called automatically when an "endl" is sent to the stream. At first the buffer content is wrapped in the prefix and suffix messages, then the entire string is written to the file by calling flushBuffer(). Finally, the internal buffers are reset.
Definition at line 454 of file infoout.cpp.
|
private |