MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
InfoOutStream Class Reference

Class to create an output stream that writes to cout or cerr but prepends each line with the MPI rank. More...

#include <infoout.h>

Inheritance diagram for InfoOutStream:
[legend]
Collaboration diagram for InfoOutStream:
[legend]

Public Member Functions

 InfoOutStream ()
 Default construtor creates InfoOutStream that is not (yet) usable. More...
 
 InfoOutStream (std::ostream *os, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool printDomainId=true)
 Constructor creates InfoOut_streamBuffer buffer and calls ostream constructor with reference to it. More...
 
 ~InfoOutStream ()
 Destructor deletes the internal buffer object. More...
 
void initialize (std::ostream *os, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool printDomainId=true)
 Passes the parameters to a call of InfoOut_streamBuffer::initialize(). More...
 
MBool setRootOnly (MBool rootOnly=true)
 Sets interal state of whether only the root domain (rank 0) should write to file. Author Michael Schlottke. 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

MBool m_isInitialized
 Stores whether a stream was already opened or not. More...
 

Additional Inherited Members

- Protected Attributes inherited from InfoOut
InfoOut_bufferm_buffer = nullptr
 

Detailed Description

Author
Michael Schlottke
Date
June 2012

This class can be used to write to an already existing output stream. The usage and behavior is just like with existing C++ output streams such as cout/cerr, except that it offers the possibility to prepend each line with information about the current MPI domain id. In future implementations it might be worth considering to add even more information to each message.

Definition at line 243 of file infoout.h.

Constructor & Destructor Documentation

◆ InfoOutStream() [1/2]

InfoOutStream::InfoOutStream ( )
Author
Michael Schlottke
Date
April 2012

When this constructor is used, initialize() needs to be called before the stream can be used.

Definition at line 1070 of file infoout.cpp.

1070 : m_isInitialized(false) {
1071 // Nothing here
1072}
MBool m_isInitialized
Stores whether a stream was already opened or not.
Definition: infoout.h:245

◆ InfoOutStream() [2/2]

InfoOutStream::InfoOutStream ( std::ostream *  os,
MPI_Comm  mpiComm = MPI_COMM_WORLD,
MBool  printDomainId = true 
)
Author
Michael Schlottke
Date
April 2012

When this constructor is used, the stream is immediately ready to use. For information about the paramters, please have a look at InfoOut_streamBuffer::initialize.

Parameters
[in]osOutput stream that should be used for output.
[in]mpiCommMPI communicator for which the domain information should be gathered.
[in]printDomainIdDetermines whether the domain id should be prepended to each message.

Definition at line 1085 of file infoout.cpp.

1085 : m_isInitialized(false) {
1086 initialize(os, mpiComm, printDomainId);
1087}
void initialize(std::ostream *os, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool printDomainId=true)
Passes the parameters to a call of InfoOut_streamBuffer::initialize().
Definition: infoout.cpp:1112

◆ ~InfoOutStream()

InfoOutStream::~InfoOutStream ( )
Author
Michael Schlottke
Date
June 2012

Definition at line 1095 of file infoout.cpp.

1095 {
1096 if(m_isInitialized) {
1097 delete m_buffer;
1098 m_isInitialized = false;
1099 }
1100}
InfoOut_buffer * m_buffer
Definition: infoout.h:82

Member Function Documentation

◆ initialize()

void InfoOutStream::initialize ( std::ostream *  os,
MPI_Comm  mpiComm = MPI_COMM_WORLD,
MBool  printDomainId = true 
)
Author
Michael Schlottke
Date
April 2012
Parameters
[in]osOutput stream that should be used for output.
[in]mpiCommMPI communicator for which the domain information should be gathered.
[in]printDomainIdDetermines whether the domain id should be prepended to each message.

Definition at line 1112 of file infoout.cpp.

1112 {
1113 if(!m_isInitialized) {
1114 m_buffer = new InfoOut_streamBuffer(os, mpiComm, printDomainId);
1115
1116 // Associate the stream with the newly created buffer
1117 rdbuf(m_buffer);
1118
1119 // Set state variable
1120 m_isInitialized = true;
1121 }
1122}
Customized string buffer to prepend cout/cerr with the domain id.
Definition: infoout.h:185

◆ setRootOnly()

MBool InfoOutStream::setRootOnly ( MBool  rootOnly = true)
virtual
Date
June 2012

\params[in] rootOnly If true, only rank 0 of the specified MPI communicator writes to file.

Returns
The previous internal state (may be stored to return to the previous behavior).

Implements InfoOut.

Definition at line 1132 of file infoout.cpp.

1132{ return m_buffer->setRootOnly(rootOnly); }
virtual MBool setRootOnly(MBool rootOnly=true)
Sets interal state of whether only the root domain (rank 0) should write to file.
Definition: infoout.cpp:173

Member Data Documentation

◆ m_isInitialized

MBool InfoOutStream::m_isInitialized
private

Definition at line 245 of file infoout.h.


The documentation for this class was generated from the following files: