Why is my MPI program outputting incorrectly

前端 未结 2 647
青春惊慌失措
青春惊慌失措 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.

提交回复
热议问题