title: Gracefully exit with MPI
body: <p>I'm trying to gracefully exit my program after if Rdinput returns an error.</p>
  
  <pre><code>#include &lt;mpi.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define MASTER 0
  #define Abort(x) MPI_Abort(MPI_COMM_WORLD, x)
  #define Bcast(send_data, count, type) MPI_Bcast(send_data, count, type, MASTER, GROUP) //root --&gt; MASTER
  #define Finalize() MPI_Finalize()
  
  int main(int argc, char **argv){
  
    //Code
  
    if( rank == MASTER ) {
      time (&amp;start);
      printf("Initialized at %s\n", ctime (&amp;start) );      
      //Read file
      error = RdInput();
    }
  
    Bcast(&amp;error, 1, INT); Wait();
  
    if( error = 1 ) MPI_Abort(1);
  
    //Code
  
    Finalize();
  }
  </code></pre>
  
  <p>Program output:</p>
  
  <pre><code>mpirun -np 2 code.x 
  --------------------------------------------------------------------------
  MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD 
  with errorcode 1.
  
  NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
  You may or may not see output from other processes, depending on
  exactly when Open MPI kills them.
  --------------------------------------------------------------------------
  Initialized at Wed May 30 11:34:46 2012
  Error [RdInput]: The file "input.mga" is not available!
  --------------------------------------------------------------------------
  mpirun has exited due to process rank 0 with PID 7369 on
  node einstein exiting improperly. There are two reasons this could occur:
  
  //More error message.
  </code></pre>
  
  <p>What can I do to gracefully exit an MPI program without printing this huge error message?</p>