Home > Uncategorized > Open MPI and flushing printf (or cout)

Open MPI and flushing printf (or cout)

When you have printf (or cout) in your MPI program,situation may occur that printing is just not working. And worst of all, somewhere in the middle of the program, printing will work.

For example, following code:

printf("Please enter number: ");
scanf("%d", &m);

will not display "Please enter number:" message, but scanf will work, and you can enter the number

Why?

Open MPI will flush output buffer to the display, only after \n (new line) character is found (or std::endl if using c++ iostream)

Following code, will work as expected:

printf("Please enter number:\n");
scanf("%d", &m);

note that ‘\n’ (new line) is at the end of printf string

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: