Proposed fix for std::cout sync bug in output.cpp #2122
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a non-MPI version of the code is compiled and run, print to std::cout is corrupted. Carriage returns appear in the wrong places, and data columns appear as a single line. This behaviour has not been seen when compiled for MPI.
One possible fix presented here replaces the offending stream directs of the form std::cout << std::endl with calls to fmt::print. The problem appears to be mixing the two output methods. Alternative fixes are probably possible.
I've not been able to explain his behaviour, or why compiling with MPI corrects the issue. Presumably fmtlib maintains its own print buffer for performance which is flushed at a different rate to std::cout. A possible complicating factor is that std::endl both introduces a carriage return and flushes the buffer. Perhaps compiling with MPI overrides the default std::cout behaviour.
I've left references to std::cout in other areas of the code. It may be prudent to remove them.
I've been unable to test this code since I can't get the Dockerfile to compile. However, since these are trivial changes I've decided to submit these changes for your review.