This has little to do specifically with MPI and is a pretty normal Unix I/O behaviour. The standard output stream is line buffered, which means that nothing is being sent to the underlying I/O subsystem unless a new line is encountered in the stream or a flush operation is enforced.
Compare the following: printf("asdasd");
and printf("asdasd\n");
. In the first case, asdasd
is appended to the buffer of the stdout
stream, but since there is no new line there, the buffer is not flushed and nothing is actually sent to the terminal. In the second case asdasd
is appended to the output stream and then the presence of the new line results in an automatic flush, therefore asdasd<new line>
is what you see immediately. As already shown by John Zwinck, fflush(stdout);
can be used to forcefully flush the stream buffer.
Note that if you come from Windows backgroud, the standard output there is not line buffered and printf("asdasd");
does result in adsasd
being outputted without a following explicit flush operation. But then, even on Windows, it is possible that the I/O redirection mechanism of MPI is line buffered.