Gracefully exit with MPI

前端 未结 1 1617
旧巷少年郎
旧巷少年郎 2021-02-11 06:36

I\'m trying to gracefully exit my program after if Rdinput returns an error.

#include 
#include 
#include 

#define M         


        
相关标签:
1条回答
  • 2021-02-11 07:16

    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.

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