15 #include "ParallelBuffer.h"
16 #include "Utilities.h"
26 const int ParallelBuffer::DEFAULT_BUFFER_SIZE = 128;
39 MPI_Initialized(&mpi_init);
42 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
48 d_ostream = &std::cerr;
80 const std::string& text,
89 d_buffer =
new char[DEFAULT_BUFFER_SIZE];
90 d_buffer_size = DEFAULT_BUFFER_SIZE;
97 if (d_buffer_ptr == 0) {
98 copyToBuffer(d_prefix,
static_cast<int>(d_prefix.length()));
106 for ( ; (eol_ptr < length) && (text[eol_ptr] !=
'\n'); eol_ptr++) {}
114 if (eol_ptr == length) {
115 copyToBuffer(text, length);
117 const int ncopy = eol_ptr + 1;
118 copyToBuffer(text, ncopy);
120 if (ncopy < length) {
138 const int n =
static_cast<int>(pptr() - pbase());
157 #if !defined(__INTEL_COMPILER) && (defined(__GNUG__))
159 ParallelBuffer::xsputn(
160 const std::string& text,
181 const int n =
static_cast<int>(pptr() - pbase());
187 character[0] = (char)ch;
205 ParallelBuffer::copyToBuffer(
206 const std::string& text,
212 if (d_buffer_ptr + length > d_buffer_size) {
214 if (d_buffer_ptr + length > 2 * d_buffer_size) {
215 new_size = d_buffer_ptr + length;
218 new_size = 2 * d_buffer_size;
220 char* new_buffer =
new char[new_size];
222 if (d_buffer_ptr > 0) {
223 (void)strncpy(new_buffer, d_buffer, d_buffer_ptr);
227 d_buffer = new_buffer;
228 d_buffer_size = new_size;
230 CAROM_ASSERT(d_buffer_ptr + length <= d_buffer_size);
235 strncpy(d_buffer + d_buffer_ptr, text.c_str(), length);
236 d_buffer_ptr += length;
248 ParallelBuffer::outputBuffer()
250 if (d_buffer_ptr > 0) {
252 d_ostream->write(d_buffer, d_buffer_ptr);
int overflow(int ch)
Write an overflow character into the parallel buffer (called from streambuf).
int sync()
Synchronize the parallel buffer (called from streambuf).
~ParallelBuffer()
Destructor.
ParallelBuffer()
Default constructor.
void outputString(const std::string &text)
Write a text string to the output stream.
static std::string processorToString(int processorID)
Converts a processor ID to a string. Use this to ensure same width is used when converting a processo...