MAIA bb96820c
Multiphysics at AIA
|
Customized buffer to facilitate MPI I/O usage for a single file for all domains within an MPI communicator. More...
#include <infoout.h>
Public Member Functions | |
InfoOut_mpiFileBuffer () | |
Generic constructor is used when no information is provided during declaration. More... | |
InfoOut_mpiFileBuffer (const MString &filename, const MString &projectName, MPI_Comm mpiComm=MPI_COMM_WORLD) | |
This constructor yields a new instance that can immediately be used to write messages to an MPI file. More... | |
~InfoOut_mpiFileBuffer () | |
Destructor calls close() to close the MPI file (if opened) and deletes the MPI write buffer. More... | |
void | open (const MString &filename, const MString &projectName, MPI_Comm mpiComm=MPI_COMM_WORLD) |
Initialization of the MPI I/O environment. More... | |
void | close (MBool forceClose=false) |
Closes the MPI 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_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 if flushing conditions are met. More... | |
virtual void | flushBuffer () |
Flushes the buffer by writing the contents to the MPI 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 Member Functions | |
MInt | setMpiWriteBuffer (MInt newBufferSize) |
Delete the current MPI write buffer and allocate a new one. More... | |
Private Attributes | |
MInt | m_maxMessageLength |
Maximum message length (excluding formatting) More... | |
MInt | m_mpiWriteBufferSize |
Size of the MPI write buffer. More... | |
MChar * | m_mpiWriteBuffer |
MPI write buffer. More... | |
MBool | m_isOpen |
Stores whether the MPI file was already opened. More... | |
MString | m_filename |
Filename on disk. More... | |
MPI_Comm | m_mpiComm |
MPI communicator group. More... | |
MPI_File | m_mpiFileHandle |
MPI file handle. More... | |
MPI_Request | m_mpiRequest |
MPI request object (nonblocking I/O) More... | |
Static Private Attributes | |
static const MInt | m_maxStringLength = 8192 |
Maximum string length (including formatting, default: 4096) 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 MPI I/O. The entire MPI communication is hidden from the user, so that the underlying algorithms can be changed/optimized without affecting current implementations.
Internally, an XML file is created to store all messages with each processor's MPI rank so that each message can be attributed to the origin. The XML format ensures that fast and easy-to-develop post processing tools may be used (e.g. extractdomainlog.py). Additionally, meta information about the total number of domains as well as the creation/closing date of the file is saved.
InfoOut_mpiFileBuffer::InfoOut_mpiFileBuffer | ( | ) |
Definition at line 504 of file infoout.cpp.
InfoOut_mpiFileBuffer::InfoOut_mpiFileBuffer | ( | const MString & | filename, |
const MString & | projectName, | ||
MPI_Comm | mpiComm = MPI_COMM_WORLD |
||
) |
Internally, this constructor just passes the parameters to open() (see open() for more details).
[in] | filename | Filename that should be used for the MPI file. |
[in] | mpiComm | MPI communicator for which the file should be opened. |
[in] | m_projectName | Projectname given. |
Definition at line 526 of file infoout.cpp.
InfoOut_mpiFileBuffer::~InfoOut_mpiFileBuffer | ( | ) |
The MPI write buffer m_mpiWriteBuffer is deleted as well, since it could be that the buffer is allocated using setMinFlushSize() but never opened with open() (and thus not deleted within close()).
Definition at line 545 of file infoout.cpp.
void InfoOut_mpiFileBuffer::close | ( | MBool | forceClose = false | ) |
Any subsequent write statements to the MPI file stream are discarded after this method is called. NOTE: If the MPI file is not closed using this function before MPI_Finalize() is called, an MPI error occurs!
After close() is called, the MPI root process first writes an XML footer to the file. Then the file is
closed on all ranks.
Definition at line 629 of file infoout.cpp.
|
inlineprotectedvirtual |
This method flushes the buffer (i.e. copy the buffer to the MPI write buffer, issue the MPI commands etc.) if the file is open, and if this processor is supposed to write to the file. It ignores any settings for the minimum flush size, and assumes that all string formatting was already performed.
Implements InfoOut_buffer.
Definition at line 714 of file infoout.cpp.
void InfoOut_mpiFileBuffer::open | ( | const MString & | filename, |
const MString & | projectName, | ||
MPI_Comm | mpiComm = MPI_COMM_WORLD |
||
) |
After a successful call to this method the MPI 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. The root process also writes the necessary XML header information to the file.
[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 566 of file infoout.cpp.
This calls InfoOut_buffer::setMinFlushSize and then adds some code to change the size of the MPI write buffer m_mpiWriteBuffer along with the minFlushSize.
\params[in] minFlushSize Minimum buffer length.
Reimplemented from InfoOut_buffer.
Definition at line 742 of file infoout.cpp.
This method calls MPI_Wait to make sure that all write statements have completed before the buffer is deleted. Then m_mpiWriteBuffer is deleted and afterwards recreated with the new buffer size.
\params[in] newBufferSize The new size of the write buffer
Definition at line 765 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 MPI file using nonblocking communication by calling flushBuffer(). Finally the internal buffers are reset.
Definition at line 677 of file infoout.cpp.
|
staticprivate |