Gracefully exit with MPI

为君一笑 提交于 2019-12-03 21:00:40

If you have this logic in your code:

Bcast(&error, 1, INT);
if( error = 1 ) MPI_Abort(1); 

then you're just about done (although you don't need any kind of wait after a broadcast). The trick, as you've discovered, is that MPI_Abort() does not do "graceful"; it basically is there to shut things down in whatever way possible when something's gone horribly wrong.

In this case, since now everyone agrees on the error code after the broadcast, just do a graceful end of your program:

   MPI_Bcast(&error, 1, MPI_INT, MASTER, MPI_COMM_WORLD);
   if (error != 0) {
       if (rank == 0) {
           fprintf(stderr, "Error: Program terminated with error code %d\n", error);
       }
       MPI_Finalize();
       exit(error);
   } 

It's an error to call MPI_Finalize() and keep on going with more MPI stuff, but that's not what you're doing here, so you're fine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!