Skip to content

Commit

Permalink
Fix flush
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 20, 2024
1 parent 4c5b4af commit 11ba127
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ template <typename F> class apple_file : public file_base<F> {
auto get_write_buffer() const -> span<char> {
if (!this->file_->_p || offset() == this->file_->_bf._size) {
// Force buffer initialization by placing and removing a char in a buffer.
fputc(0, this->file_);
putc_unlocked(0, this->file_);
--this->file_->_p;
++this->file_->_w;
}
Expand Down Expand Up @@ -1571,6 +1571,7 @@ class file_print_buffer : public buffer<char> {
static void grow(buffer<char>& buf, size_t) {
auto& self = static_cast<file_print_buffer&>(buf);
self.set_buffer();
self.clear();
}

public:
Expand Down

4 comments on commit 11ba127

@b0ae989c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this fix does not address the flushing issue in parallel code (MPI and UPC++ specifically). Maybe we should add a comment in docs to remind users to invoke stream flush explicitly?

@vitaut
Copy link
Contributor Author

@vitaut vitaut commented on 11ba127 Jan 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b0ae989c what issue are you referring to?

@b0ae989c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting at commit 6b68dff, the behavior of fmt::print changes when it's used in a parallel context that involves multiple computing nodes. Even with this commit fix, the following program does not output anything until the very end of the simulation

auto main() -> int {
  fmt::print("test begins\n");
  // Other work. This part of the program needs a few days to finish.
  fmt::print("test ends\n");
  return 0;
}

The old behavior is that "test begins" is written to the output logs before the time consuming work starts. Right now, this line is not written to logs until the entire program finishes (after several days).

We manage to fix this by adding std::cout << std::flush; after every fmt::print calls. Note that this issue does not appear in sequential code.

@vitaut
Copy link
Contributor Author

@vitaut vitaut commented on 11ba127 Jan 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b0ae989c, should be fixed in 6435b16 which adds line buffering support.

Please sign in to comment.