MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
infoout.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#include "infoout.h"
8
9#include <algorithm> // Needed for string replace function
10#include <iomanip> // Needed for formatted output
11#include <iostream> // Needed for ostream
12#include "compiler_config.h"
13#if defined(MAIA_MS_COMPILER)
14#include <Windows.h>
15#include <Winsock2.h>
16#include <direct.h>
17#else
18#include <pwd.h>
19#include <unistd.h>
20#endif
21#include <sys/types.h>
22#include <time.h> // Needed for generating time strings
23#include "COMM/mpioverride.h"
24#include "UTIL/functions.h"
25#include "environment.h"
26
27// Needed for the different InfoOutFile filetypes
28using namespace MAIA_INFOOUT_FILETYPES;
29using namespace std;
30
38MInt InfoOut::addAttribute(pair<MString, MString> att) {
39 m_buffer->m_prefixAttributes.push_back(att);
41 return m_buffer->m_prefixAttributes.size() - 1;
42}
43
53}
54
62void InfoOut::modifyAttribute(MInt attId, pair<MString, MString> att) {
63 m_buffer->m_prefixAttributes[attId] = att;
65}
66
73 : m_rootOnly(false),
74 m_domainId(0),
75 m_noDomains(1),
76 m_minFlushSize(0),
77 m_prefixMessage(),
78 m_suffixMessage(),
79 m_tmpBuffer(),
80 m_projectName() {
81 // Nothing here
82}
83
96 MChar c; // Contains the current character
97 ostringstream tmpEncodeBuffer; // Used as a temporary string buffer
98
99 // Create a for loop that uses an iterator to traverse the complete string
100 for(MString::const_iterator iter = inputStr.begin(); iter < inputStr.end(); iter++) {
101 // Get current character
102 c = (MChar)*iter;
103
104 // Use a switch/case statement for the five XML entities
105 switch(c) {
106 case '"':
107 tmpEncodeBuffer << "&quot;";
108 break; // Replace double quotes
109 case '&':
110 tmpEncodeBuffer << "&amp;";
111 break; // Replace ampersand
112 case '\'':
113 tmpEncodeBuffer << "&apos;";
114 break; // Replace single quote
115 case '<':
116 tmpEncodeBuffer << "&lt;";
117 break; // Replace less-than sign
118 case '>':
119 tmpEncodeBuffer << "&gt;";
120 break; // Replace greater-than sign
121 default:
122 tmpEncodeBuffer << c; // By default just append current character
123 }
124 }
125
126 // Return encoded stream as a string
127 return tmpEncodeBuffer.str();
128}
129
139 // Create temporary stream
140 ostringstream tmpStream;
141
142 // Fill stream with formatted domain id
143 tmpStream << "<m d=\"" << m_domainId << "\" ";
144
145 for(MInt i = 0; i < (MInt)(m_prefixAttributes.size()); i++)
146 tmpStream << m_prefixAttributes[i].first << "=\"" << m_prefixAttributes[i].second << "\" ";
147
148 tmpStream << ">";
149
150 // Set prefix message to tmpBuffer string
151 m_prefixMessage = tmpStream.str();
152
153 // Reset buffer
154 tmpStream.str("");
155}
156
163
164
174 MBool previousValue = m_rootOnly;
175 m_rootOnly = rootOnly;
176 return previousValue;
177}
178
188 MInt previousValue = m_minFlushSize;
189 m_minFlushSize = minFlushSize;
190 return previousValue;
191}
192
200 const MInt maxNoChars = 1024;
201
202 // Gets the current hostname
203 MChar host[maxNoChars];
204 gethostname(host, maxNoChars - 1);
205 host[maxNoChars - 1] = '\0';
206
207 // Gets the current username
208 MString user;
209#if defined(MAIA_MS_COMPILER)
210 constexpr MInt INFO_BUFFER_SIZE = 32767;
211 TCHAR infoBuf[INFO_BUFFER_SIZE];
212 DWORD bufCharCount = INFO_BUFFER_SIZE;
213 if(!GetUserName(infoBuf, &bufCharCount)) {
214 user = "n/a";
215 } else {
216 user = infoBuf;
217 }
218#else
219 passwd* p;
220 p = getpwuid(getuid());
221 if(p) {
222 user = MString(p->pw_name);
223 } else {
224 user = "n/a";
225 }
226#endif
227
228 // Gets the current directory
229 MChar dir[maxNoChars];
230#if defined(MAIA_MS_COMPILER)
231 _getcwd(dir, maxNoChars - 1);
232#else
233 if(!getcwd(dir, maxNoChars - 1)) {
234 TERM(-1);
235 }
236#endif
237 dir[maxNoChars - 1] = '\0';
238
239 // Gets the current executionCommand
240 stringstream executionCommand;
241 executionCommand.str("");
242 // m_argv and m_argc additionaly described in maia.cpp
243#ifndef PVPLUGIN
244 executionCommand << Environment::m_argv[0];
245 for(MInt n = 1; n < Environment::m_argc; n++) {
246 executionCommand << " " << Environment::m_argv[n];
247 }
248#else
249 executionCommand << "paraview plugin was started --> no execution command";
250#endif
251
252
253 // Create start timestamp
254 MChar tmpDateTime[128];
255 tm* timeInfo;
256 time_t rawTime;
257
258 // Get the current time and write it to rawTime
259 time(&rawTime);
260
261 // Convert to time struct
262 timeInfo = localtime(&rawTime);
263
264 // Format time to string and save to buffer
265 strftime(tmpDateTime, 128, "%Y-%m-%d %H:%M:%S", timeInfo);
266
267 // Create temporary buffer
268 ostringstream tmpBuffer;
269
270 // Write XML header information to buffer
271 tmpBuffer << "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
272 tmpBuffer << "<root>\n";
273 tmpBuffer << "<meta name=\"noDomains\" content=\"" << m_noDomains << "\" />\n";
274 tmpBuffer << "<meta name=\"dateCreation\" content=\"" << tmpDateTime << "\" />\n";
275 tmpBuffer << "<meta name=\"fileFormatVersion\" content=\"" << m_fileFormatVersion << "\" />\n";
276 tmpBuffer << "<meta name=\"projectName\" content=\"" << m_projectName << "\" />\n";
277 tmpBuffer << "<meta name=\"user\" content=\"" << user << "\" />\n";
278 tmpBuffer << "<meta name=\"host\" content=\"" << host << " (" << XSTRINGIFY(MAIA_HOST_STRING) << ")"
279 << "\" />\n";
280 tmpBuffer << "<meta name=\"dir\" content=\"" << dir << "\" />\n";
281 tmpBuffer << "<meta name=\"executionCommand\" content=\"" << executionCommand.str() << "\" />\n";
282 tmpBuffer << "<meta name=\"revision\" content=\"" << XSTRINGIFY(MAIA_VERSION_STRING) << "\" />\n";
283 tmpBuffer << "<meta name=\"build\" content=\"" << XSTRINGIFY(MAIA_COMPILER_STRING) << " "
284 << XSTRINGIFY(MAIA_BUILD_TYPE_STRING) << " (" << MString(XSTRINGIFY(MAIA_COMPILER_VERSION_STRING)) << ")"
285 << "\" />\n";
286
287
288 // Return XML header
289 return tmpBuffer.str();
290}
291
300 // Create timestamp
301 MChar tmpDateTime[128];
302 tm* timeInfo;
303 time_t rawTime;
304
305 // Get the current time and write it to rawTime
306 time(&rawTime);
307
308 // Convert to time struct
309 timeInfo = localtime(&rawTime);
310
311 // Format time to string and save to buffer
312 strftime(tmpDateTime, 128, "%Y-%m-%d %H:%M:%S", timeInfo);
313
314 // Create temporary buffer
315 ostringstream tmpBuffer;
316
317 // Write XML footer to buffer
318 tmpBuffer << "<meta name=\"dateClosing\" content=\"" << tmpDateTime << "\" />\n";
319 tmpBuffer << "</root>\n";
320
321 // Return XML footer
322 return tmpBuffer.str();
323}
324
325
332 : m_isOpen(false), m_rootOnlyHardwired(false), m_filename(), m_file(), m_mpiComm() {
333 // Nothing here
334}
335
349 MPI_Comm mpiComm, MBool rootOnlyHardwired)
350 : m_isOpen(false), m_rootOnlyHardwired(false), m_filename(), m_file(), m_mpiComm() {
351 open(filename, projectName, mpiComm, rootOnlyHardwired);
352}
353
360
376void InfoOut_simpleFileBuffer::open(const MString& filename, const MString& projectName, MPI_Comm mpiComm,
377 MBool rootOnlyHardwired) {
378 // Open file only if it was not yet done
379 if(!m_isOpen) {
380 // Set MPI communicator group
381 m_mpiComm = mpiComm;
382
383 // Get domain id and number of domains
384 MPI_Comm_rank(m_mpiComm, &m_domainId);
385 MPI_Comm_size(m_mpiComm, &m_noDomains);
386
387 // Set whether only domain 0 should do any writing (including the creation of a file)
388 m_rootOnlyHardwired = rootOnlyHardwired;
389
390 // Only open the file if m_rootOnlyHardwired was not set as true. Otherwise the file state remains closed.
391 if(!(m_rootOnlyHardwired && m_domainId != 0)) {
392 // Set filename
393 m_filename = filename;
394
395 // Set projectName
396 m_projectName = projectName;
397
398 // Open file
399 m_file.open(m_filename.c_str());
400
401 // Clear internal buffer in order to dismiss any previous input
402 str("");
403
404 // Create prefix and suffix messages
407
408 // Write root and meta information to file
409 m_file << getXmlHeader() << flush;
410
411 // Set state variable
412 m_isOpen = true;
413 }
414 }
415}
416
425 // forceClose is not needed here (only kept for interface consistency reasons)
426 static_cast<void>(forceClose);
427
428 // Only close file if was opened before
429 if(m_isOpen) {
430 // Force flushing of the internal buffer
431 flushBuffer();
432
433 // Write XML footer to file and flush stream
434 m_file << getXmlFooter() << flush;
435
436 // Close file stream
437 m_file.close();
438
439 // Set state variable
440 m_isOpen = false;
441 }
442}
443
455 // Only write if the file was already opened
456 if(m_isOpen) {
457 // Create formatted string, escape any XML entities in the message, and save to temporary buffer
459
460 // Only write to file if current buffer length exceeds the minimum size for flushing
461 if(m_tmpBuffer.str().length() >= (unsigned)m_minFlushSize) {
462 // Write the string to the file and flush the stream
463 m_file << m_tmpBuffer.str() << flush;
464
465 // Reset temporary buffer
466 m_tmpBuffer.str("");
467 }
468 }
469
470 // Reset internal buffer
471 str("");
472
473 // Default return value for sync()
474 return 0;
475}
476
488 // Only write if the file was already opened
489 if(m_isOpen) {
490 // Write the string to the file and flush the stream
491 m_file << m_tmpBuffer.str() << flush;
492
493 // Reset temporary buffer
494 m_tmpBuffer.str("");
495 }
496}
497
498
505 : m_maxMessageLength(0),
506 m_mpiWriteBufferSize(0),
507 m_mpiWriteBuffer(0),
508 m_isOpen(false),
509 m_filename(),
510 m_mpiComm(),
511 m_mpiFileHandle(),
512 m_mpiRequest(MPI_REQUEST_NULL) {
513 // Nothing here
514}
515
526InfoOut_mpiFileBuffer::InfoOut_mpiFileBuffer(const MString& filename, const MString& projectName, MPI_Comm mpiComm)
527 : m_maxMessageLength(0),
528 m_mpiWriteBufferSize(0),
529 m_mpiWriteBuffer(0),
530 m_isOpen(false),
531 m_filename(),
532 m_mpiComm(),
533 m_mpiFileHandle(),
534 m_mpiRequest(MPI_REQUEST_NULL) {
535 open(filename, projectName, mpiComm);
536}
537
546 // Close the file
547 close();
548
549 // Delete write buffer
550 delete[] m_mpiWriteBuffer;
551}
552
566void InfoOut_mpiFileBuffer::open(const MString& filename, const MString& projectName, MPI_Comm mpiComm) {
567 // Open file only if it was not yet done
568 if(!m_isOpen) {
569 // Set MPI communicator group
570 m_mpiComm = mpiComm;
571
572 // Get domain id and number of domains
573 MPI_Comm_rank(m_mpiComm, &m_domainId);
574 MPI_Comm_size(m_mpiComm, &m_noDomains);
575
576 // Set filename
577 m_filename = filename;
578
579 // Set projectName
580 m_projectName = projectName;
581
582 // Delete log file if one exists
583 MPI_File_delete((MChar*)m_filename.c_str(), MPI_INFO_NULL);
584
585 // Set MPI config values
586 MInt amode = MPI_MODE_CREATE | MPI_MODE_WRONLY;
587
588 // Open MPI file
589 MPI_File_open(m_mpiComm, (MChar*)m_filename.c_str(), amode, MPI_INFO_NULL, &m_mpiFileHandle, AT_);
590
591 // Clear internal buffer in order to dismiss any previous input
592 str("");
593
594 // Create prefix and suffix messages and calculate the maximum length for a message
598
599 // Create new write buffer with the following size: length before flushing + max MPI string length
601
602 // Write root and meta information to log file (only on MPI root, i.e. domain id == 0)
603 if(m_domainId == 0) {
604 // Copy buffer string to MPI buffer
605 MInt mpiStringLength = getXmlHeader().copy(m_mpiWriteBuffer, m_mpiWriteBufferSize);
606
607 // Write to MPI file
608 MPI_File_write_shared(m_mpiFileHandle, m_mpiWriteBuffer, mpiStringLength, MPI_CHAR, MPI_STATUS_IGNORE, AT_);
609 }
610
611 // Make sure that initial message is written before file is used
613
614 // Set state variable
615 m_isOpen = true;
616 }
617}
618
630 // Only perform finalization if this instance was initialized before
631 if(m_isOpen) {
632 // Only perform cleanup if forceClose is not set to true
633 if(!forceClose) {
634 // Force flushing of the internal buffer
635 flushBuffer();
636
637 // Call MPI_Wait to make sure everything was written to disk
638 MPI_Wait(&m_mpiRequest, MPI_STATUS_IGNORE, AT_);
639
640 // Make sure that all processes have finished writing, so that the footer can be written before the file is closed
642
643 // Write root information to log file (only on MPI root)
644 if(m_domainId == 0) {
645 // Copy buffer string to MPI buffer
646 MInt mpiStringLength = getXmlFooter().copy(m_mpiWriteBuffer, m_mpiWriteBufferSize);
647
648 // Write to MPI file
649 MPI_File_write_shared(m_mpiFileHandle, m_mpiWriteBuffer, mpiStringLength, MPI_CHAR, MPI_STATUS_IGNORE, AT_);
650 }
651
652 // Close MPI file
654 }
655
656 // Delete MPI write buffer
657 delete[] m_mpiWriteBuffer;
658
659 // Set pointer to null to avoid problems when the destructor calls delete again
661
662 // Reset state variable
663 m_isOpen = false;
664 }
665}
666
678 // Only write to MPI if the MPI file was already opened, and only if we're supposed to on this domain
679 if(m_isOpen && !(m_rootOnly && m_domainId != 0)) {
680 // Escape XML entities in buffer
681 str(encodeXml(str()));
682
683 // Create formatted string and write to temporary buffer
684 if(str().length() > (unsigned)m_maxMessageLength) {
685 // If buffer content + prefix/suffix message is too long for m_mpiWriteBuffer, use substr and ensure a newline at
686 // the end. In substr the '-1' is for the newline character.
687 m_tmpBuffer << m_prefixMessage << str().substr(0, m_maxMessageLength - 1) << "\n" << m_suffixMessage;
688 } else {
689 // Otherwise just copy the whole string
691 }
692
693 // Only write to MPI file if current buffer length exceeds the minimum size for flushing
694 if(m_tmpBuffer.str().length() >= (unsigned)m_minFlushSize) {
695 flushBuffer();
696 }
697 }
698
699 // Reset internal buffer
700 str("");
701
702 // Default return value for sync()
703 return 0;
704}
705
715 // Only write to MPI if the MPI file was already opened, and only if we're supposed to on this domain
716 if(m_isOpen && !(m_rootOnly && m_domainId != 0)) {
717 // Before copying the new string into the write buffer, make sure that the previous MPI write has finished
718 MPI_Wait(&m_mpiRequest, MPI_STATUS_IGNORE, AT_);
719
720 // Retrieve actual string length while copying the string from the temporary buffer to the write buffer.
721 // The copy command is invoked with the current buffer size to ensure that there is no buffer overflow.
722 MInt mpiStringLength = m_tmpBuffer.str().copy(m_mpiWriteBuffer, m_mpiWriteBufferSize);
723
724 // Reset temporary buffer
725 m_tmpBuffer.str("");
726
727 // Write mpiStringLength characters to file using nonblocking MPI I/O
728 MPI_File_iwrite_shared(m_mpiFileHandle, m_mpiWriteBuffer, mpiStringLength, MPI_CHAR, &m_mpiRequest, AT_);
729 }
730}
731
743 // Call base class method for general stuff
744 MInt previousValue = InfoOut_buffer::setMinFlushSize(minFlushSize);
745
746 // Flush current buffer
747 flushBuffer();
748
749 // Create new write buffer with the following size: length before flushing + max MPI string length
751
752 return previousValue;
753}
754
766 // Make sure that the write buffer is empty
767 MPI_Wait(&m_mpiRequest, MPI_STATUS_IGNORE, AT_);
768
769 // Delete old write buffer
770 delete[] m_mpiWriteBuffer;
771
772 // Create new write buffer
773 m_mpiWriteBuffer = new MChar[newBufferSize];
774
775 // Save old buffer size to temporary variable and new buffer size to member variable
776 MInt oldBufferSize = m_mpiWriteBufferSize;
777 m_mpiWriteBufferSize = newBufferSize;
778
779 // Return the previous buffer size
780 return oldBufferSize;
781}
782
783
790 : m_isInitialized(false), m_printDomainId(false), m_output(0), m_mpiComm(), m_isDisabled(false) {
791 // Nothing here
792}
793
803InfoOut_streamBuffer::InfoOut_streamBuffer(ostream* os, MPI_Comm mpiComm, MBool printDomainId)
804 : m_isInitialized(false), m_printDomainId(false), m_output(0), m_mpiComm(), m_isDisabled(false) {
805 initialize(os, mpiComm, printDomainId);
806}
807
820void InfoOut_streamBuffer::initialize(ostream* os, MPI_Comm mpiComm, MBool printDomainId) {
821 // Delete any previous (non-empty) strings stored in the buffer that were not flushed yet by calling sync
822 if(!str().empty()) {
823 sync();
824 }
825
826 // Assign ostream to m_output
827 m_output = os;
828
829 // Set MPI communicator group
830 m_mpiComm = mpiComm;
831
832 // Save whether the domain id should be prepended to each message
833 m_printDomainId = printDomainId;
834
835 // Get domain id
836 MPI_Comm_rank(m_mpiComm, &m_domainId);
837
838 // Create prefix string including the domain id if specified
839 if(m_printDomainId) {
840 // Create temporary stream
841 ostringstream tmpStream;
842
843 // Fill tmpStream with formatted domain id
844 tmpStream << "[" << setfill('0') << setw(7) << m_domainId << "] ";
845
846 // Set prefix message to tmpStream string
847 m_prefixMessage = tmpStream.str();
848 } else {
849 // Otherwise use an empty prefix message
850 m_prefixMessage = "";
851 }
852
853 // Set state variable
854 m_isInitialized = true;
855
856 // Set isDisabled
857 m_isDisabled = false;
858}
859
868 MChar c;
869 ostringstream tmpEncodeStreambuffer;
870
871 for(MString::const_iterator iter = inputStr.begin(); iter < inputStr.end(); iter++) {
872 c = (MChar)*iter;
873 tmpEncodeStreambuffer << c;
874
875 if(c == '\n' && iter != inputStr.end() - 1) {
876 tmpEncodeStreambuffer << m_prefixMessage;
877 }
878 }
879
880 return tmpEncodeStreambuffer.str();
881}
882
883
895 // Only write actual output if streamBuffer is initialized, and if we are supposed to on this processor
896 if(m_isInitialized && !(m_rootOnly && m_domainId != 0) && !m_isDisabled) {
897 // Create formatted string
899
900 // Write temporary buffer to output stream and flush it
901 *m_output << m_tmpBuffer.str() << flush;
902 }
903
904 // Reset stringbuf of InfoOut_streamBuffer
905 str("");
906
907 // Reset temporary buffer
908 m_tmpBuffer.str("");
909
910 // Default return value for sync()
911 return 0;
912}
913
920 // Nothing here
921}
922
923
930InfoOutFile::InfoOutFile() : m_fileType(0), m_isOpen(false) {
931 // Nothing here
932}
933
945InfoOutFile::InfoOutFile(const MString& filename, const MString& projectName, MInt fileType, MPI_Comm mpiComm,
946 MBool rootOnlyHardwired)
947 : m_fileType(0), m_isOpen(false) {
948 open(filename, projectName, fileType, mpiComm, rootOnlyHardwired);
949}
950
957
975void InfoOutFile::open(const MString& filename, const MString& projectName, MInt fileType, MPI_Comm mpiComm,
976 MBool rootOnlyHardwired) {
977 // Only open file if it was not yet opened
978 if(!m_isOpen) {
979 // Save file type to member variable
980 m_fileType = fileType;
981
982 // Create a new buffer object depending on the specified file type
983 switch(m_fileType) {
985 // Open a simple file
986 m_buffer = new InfoOut_simpleFileBuffer(filename, projectName, mpiComm, rootOnlyHardwired);
987 break;
989 // Open an MPI file
990 default:
991 // This is also the default behavior if no valid fileType was specified (or none at all).
993 m_buffer = new InfoOut_mpiFileBuffer(filename, projectName, mpiComm);
994 break;
995 }
996
997 // Associate the stream with the newly created buffer
998 rdbuf(m_buffer);
999
1000 // Set state variable
1001 m_isOpen = true;
1002 }
1003}
1004
1011void InfoOutFile::close(MBool forceClose) {
1012 // Only close file if was already opened
1013 if(m_isOpen) {
1014 // Determine correct cast by evaluating internal file type variable
1015 switch(m_fileType) {
1017 static_cast<InfoOut_simpleFileBuffer*>(m_buffer)->close(forceClose);
1018 break;
1020 static_cast<InfoOut_mpiFileBuffer*>(m_buffer)->close(forceClose);
1021 break;
1022 default: {
1023 mTerm(1, AT_, "Unknown file type");
1024 }
1025 }
1026
1027 // Delete internal buffer to prevent memory leaks
1028 delete m_buffer;
1029
1030 // Set state variable
1031 m_isOpen = false;
1032 }
1033}
1034
1044
1056 if(m_isOpen) {
1057 return m_buffer->setMinFlushSize(minFlushSize);
1058 } else {
1059 return 0;
1060 }
1061}
1062
1063
1070InfoOutStream::InfoOutStream() : m_isInitialized(false) {
1071 // Nothing here
1072}
1073
1085InfoOutStream::InfoOutStream(ostream* os, MPI_Comm mpiComm, MBool printDomainId) : m_isInitialized(false) {
1086 initialize(os, mpiComm, printDomainId);
1087}
1088
1089
1096 if(m_isInitialized) {
1097 delete m_buffer;
1098 m_isInitialized = false;
1099 }
1100}
1101
1111// Pass call to initialize to streamBuffer
1112void InfoOutStream::initialize(ostream* os, MPI_Comm mpiComm, MBool printDomainId) {
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}
1123
static MChar ** m_argv
Definition: environment.h:29
static MInt m_argc
Reads the name of the property-file and creates a new Application.
Definition: environment.h:28
MInt m_minFlushSize
Minimum length of the internal buffer before flushing.
Definition: infoout.h:49
MInt m_domainId
Contains the MPI rank (= domain id) of this process.
Definition: infoout.h:47
virtual MInt setMinFlushSize(MInt minFlushSize)
Sets the minimum buffer length that has to be reached before the buffer is flushed.
Definition: infoout.cpp:187
InfoOut_buffer()
Generic constructor is used when no information is provided during declaration.
Definition: infoout.cpp:72
MString m_prefixMessage
Stores the prefix that is prepended to each output.
Definition: infoout.h:50
MString m_suffixMessage
Stores the suffix that is apended to each output.
Definition: infoout.h:51
std::ostringstream m_tmpBuffer
Temporary buffer to hold string until flushing.
Definition: infoout.h:52
virtual void createSuffixMessage()
Creates an XML suffix that is appended to each message.
Definition: infoout.cpp:162
std::vector< std::pair< MString, MString > > m_prefixAttributes
Definition: infoout.h:55
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
virtual MString getXmlHeader()
Return an XML header that should written at the beginning of each log file.
Definition: infoout.cpp:199
virtual void createPrefixMessage()
Creates an XML prefix using the domain id that is prepended to each message.
Definition: infoout.cpp:138
MInt m_noDomains
Contains the MPI rank count (= number of domains)
Definition: infoout.h:48
MString m_projectName
Name of the current Project.
Definition: infoout.h:53
MBool m_rootOnly
Stores whether only the root domain writes a log file.
Definition: infoout.h:46
virtual MString encodeXml(const std::string &str)
Parses the string input and returns the string with XML entities escaped.
Definition: infoout.cpp:95
static const MInt m_fileFormatVersion
Definition: infoout.h:44
virtual MString getXmlFooter()
Return an XML footer that should written at the end of each log file.
Definition: infoout.cpp:299
Customized buffer to facilitate MPI I/O usage for a single file for all domains within an MPI communi...
Definition: infoout.h:114
void close(MBool forceClose=false)
Closes the MPI file.
Definition: infoout.cpp:629
MChar * m_mpiWriteBuffer
MPI write buffer.
Definition: infoout.h:119
virtual void flushBuffer()
Flushes the buffer by writing the contents to the MPI file.
Definition: infoout.cpp:714
MBool m_isOpen
Stores whether the MPI file was already opened.
Definition: infoout.h:120
MInt setMpiWriteBuffer(MInt newBufferSize)
Delete the current MPI write buffer and allocate a new one.
Definition: infoout.cpp:765
MInt m_mpiWriteBufferSize
Size of the MPI write buffer.
Definition: infoout.h:118
void open(const MString &filename, const MString &projectName, MPI_Comm mpiComm=MPI_COMM_WORLD)
Initialization of the MPI I/O environment.
Definition: infoout.cpp:566
MPI_Request m_mpiRequest
MPI request object (nonblocking I/O)
Definition: infoout.h:124
MInt m_maxMessageLength
Maximum message length (excluding formatting)
Definition: infoout.h:117
MString m_filename
Filename on disk.
Definition: infoout.h:121
MPI_File m_mpiFileHandle
MPI file handle.
Definition: infoout.h:123
virtual MInt sync()
Flushes the buffer if flushing conditions are met.
Definition: infoout.cpp:677
static const MInt m_maxStringLength
Maximum string length (including formatting, default: 4096)
Definition: infoout.h:116
MInt setMinFlushSize(MInt minFlushSize)
Sets the minimum buffer length that has to be reached before the buffer is flushed.
Definition: infoout.cpp:742
InfoOut_mpiFileBuffer()
Generic constructor is used when no information is provided during declaration.
Definition: infoout.cpp:504
~InfoOut_mpiFileBuffer()
Destructor calls close() to close the MPI file (if opened) and deletes the MPI write buffer.
Definition: infoout.cpp:545
MPI_Comm m_mpiComm
MPI communicator group.
Definition: infoout.h:122
Customized buffer to facilitate of a regular physical file for each processor within an MPI communica...
Definition: infoout.h:152
~InfoOut_simpleFileBuffer()
Destructor calls close() to close the file.
Definition: infoout.cpp:359
MString m_filename
Filename on disk.
Definition: infoout.h:156
void close(MBool forceClose=false)
Closes the file.
Definition: infoout.cpp:424
virtual void flushBuffer()
Flushes the buffer by writing the contents to the file.
Definition: infoout.cpp:487
MBool m_isOpen
Stores whether the file(s) were already opened.
Definition: infoout.h:154
virtual MInt sync()
Flushes the buffer by writing the contents to the file.
Definition: infoout.cpp:454
MBool m_rootOnlyHardwired
If true, only domain 0 opens and uses a file.
Definition: infoout.h:155
void open(const MString &filename, const MString &projectName, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool rootOnlyHardwired=false)
Initialization of the file I/O environment.
Definition: infoout.cpp:376
InfoOut_simpleFileBuffer()
Generic constructor is used when no information is provided during declaration.
Definition: infoout.cpp:331
MPI_Comm m_mpiComm
MPI communicator group.
Definition: infoout.h:158
std::ofstream m_file
File stream tied to physical file on disk.
Definition: infoout.h:157
Customized string buffer to prepend cout/cerr with the domain id.
Definition: infoout.h:185
virtual MString addPrefix(const MString &str)
Definition: infoout.cpp:867
virtual void flushBuffer()
This function does nothing for this class, since as of now there is no intermediate buffering.
Definition: infoout.cpp:919
virtual MInt sync()
Flushes the buffer by writing the contents to the asssociated output stream.
Definition: infoout.cpp:894
std::ostream * m_output
Stores the output stream (usually cout or cerr) that will be modified.
Definition: infoout.h:189
InfoOut_streamBuffer()
Default constructor does basically nothing.
Definition: infoout.cpp:789
void initialize(std::ostream *os, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool printDomainId=true)
Initializes the buffer to make it ready for use.
Definition: infoout.cpp:820
MPI_Comm m_mpiComm
MPI communicator group.
Definition: infoout.h:190
MBool m_isInitialized
Stores whether a stream was already associated with this buffer.
Definition: infoout.h:187
MBool m_isDisabled
Stores wether output in streamBuffer should be written.
Definition: infoout.h:191
MBool m_printDomainId
Stores whether the domain id should be prepended to each output.
Definition: infoout.h:188
MBool m_isOpen
Stores whether a file was already opened or not.
Definition: infoout.h:220
InfoOutFile()
Default constructor creates (virtual) file that cannot yet be used.
Definition: infoout.cpp:930
~InfoOutFile()
Destructor closes the stream.
Definition: infoout.cpp:956
MInt m_fileType
File type that is opened.
Definition: infoout.h:219
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(...).
Definition: infoout.cpp:975
void close(MBool forceClose=false)
Pass the close call to the respective internal buffer.
Definition: infoout.cpp:1011
MBool setRootOnly(MBool rootOnly=true)
Sets interal state of whether only the root domain (rank 0) should write to file.
Definition: infoout.cpp:1043
MInt setMinFlushSize(MInt minFlushSize)
Sets the minimum buffer length that has to be reached before the buffer is flushed.
Definition: infoout.cpp:1055
void modifyAttribute(MInt, std::pair< MString, MString >)
Modifies an attribute of the prefix of the XML string.
Definition: infoout.cpp:62
void eraseAttribute(MInt)
Erases an attribute from the prefix of the XML string.
Definition: infoout.cpp:50
InfoOut_buffer * m_buffer
Definition: infoout.h:82
MInt addAttribute(std::pair< MString, MString >)
Adds an attribute to the prefix of the XML string.
Definition: infoout.cpp:38
InfoOutStream()
Default construtor creates InfoOutStream that is not (yet) usable.
Definition: infoout.cpp:1070
MBool setRootOnly(MBool rootOnly=true)
Sets interal state of whether only the root domain (rank 0) should write to file. Author Michael Schl...
Definition: infoout.cpp:1132
MBool m_isInitialized
Stores whether a stream was already opened or not.
Definition: infoout.h:245
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()
Destructor deletes the internal buffer object.
Definition: infoout.cpp:1095
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
bool MBool
Definition: maiatypes.h:58
char MChar
Definition: maiatypes.h:56
int MPI_File_iwrite_shared(MPI_File mpi_fh, const void *buf, int count, MPI_Datatype datatype, MPI_Request *request, const MString &name)
same as MPI_File_iwrite_shared
int MPI_Barrier(MPI_Comm comm, const MString &name)
same as MPI_Barrier
int MPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *mpi_fh, const MString &name)
same as MPI_File_open
int MPI_Wait(MPI_Request *request, MPI_Status *status, const MString &name)
same as MPI_Wait
int MPI_File_close(MPI_File *mpi_fh, const MString &name)
same as MPI_File_close
int MPI_File_write_shared(MPI_File mpi_fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status, const MString &name)
same as MPI_File_write_shared
Namespace to hold all supported filetypes within the InfoOutFile.
Definition: infoout.h:26
const MInt MAIA_INFOOUT_SIMPLE_FILE
Use a physical file for each domain.
Definition: infoout.h:28
const MInt MAIA_INFOOUT_MPI_FILE
Use a single file for all domains (MPI I/O)
Definition: infoout.h:27