简体   繁体   English

如果进程挂在MPI_Recv上,则不会显示MPI C fprintf()输出

[英]MPI C fprintf() output not showing up if the process hangs on MPI_Recv

I'm writing an MPI C program. 我正在编写MPI C程序。 I have troubles debugging it, because whenever I use fprintf, like this: fprintf(stdout, "worker: %d", worker); 我在调试它时遇到了麻烦,因为每当我使用fprintf时,就像这样:fprintf(stdout,“ worker:%d”,worker); if the program hangs, because of some blocking MPI_Recv, I can't see any output. 如果程序由于某些MPI_Recv阻塞而挂起,我看不到任何输出。 I'm sure the line of code is reached, because I can put a return statement after the fprintf statement, in which case the process finishes execution and the output is printed. 我确定代码行已到达,因为我可以在fprintf语句之后放置一个return语句,在这种情况下,过程完成执行并输出输出。 Any ideas, on how to print (see the output) even though the process gets blocked later by Recv? 关于如何打印(请参见输出)的任何想法,即使该过程后来被Recv阻止了? I hope this makes sense. 我希望这是有道理的。

By default, stdout is line buffered, so you may want to end your debugging print calls with newlines: 默认情况下, stdout是行缓冲的,因此您可能希望以换行符结束调试打印调用:

fprintf(stdout, "workder: %d\n", worker);

If you don't want a newline, you can flush the stream yourself: 如果您不想换行,则可以自己刷新流:

fprintf(stdout, "workder: %d", worker);
fflush(stdout);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM