Why is my MPI program outputting incorrectly

前端 未结 2 644
青春惊慌失措
青春惊慌失措 2020-12-12 07:08

I am a beginner in MPI and I have a homework. I am not asking for you to solve it, I only need a hint on why my program is malfunctioning.

Here is the problem

相关标签:
2条回答
  • 2020-12-12 07:20

    That is one approach. The problem you're encountering is related to output flushing. Using printf will send data to stdout, but stdout doesn't flush immediately. Since each rank will flush at its own time (in this case most likely at the end of execution), you'll get everything at the end, and both ranks will be grouped together. The easiest solution I know which will maintain the original structure of your program is to add fflush(stdout) after each printf call. This forces the buffer to flush which will display the output.

    0 讨论(0)
  • 2020-12-12 07:29

    For anyone who might be looking for the answer, i managed to find out that you should let one process handle all the printing.

    0 讨论(0)
提交回复
热议问题