-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpid/ch3/src/mpid_abort.c
        -:    0:Graph:mpid_abort.gcno
        -:    0:Data:mpid_abort.gcda
        -:    0:Runs:3459
        -:    0:Programs:899
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:/*
        -:    3: *  (C) 2001 by Argonne National Laboratory.
        -:    4: *      See COPYRIGHT in top-level directory.
        -:    5: */
        -:    6:
        -:    7:#include "mpidimpl.h"
        -:    8:
        -:    9:/* FIXME: Who uses/sets MPIDI_DEV_IMPLEMENTS_ABORT? */
        -:   10:#ifdef MPIDI_DEV_IMPLEMENTS_ABORT
        -:   11:#ifdef USE_PMI2_API
        -:   12:#include "pmi2.h"
        -:   13:#else
        -:   14:#include "pmi.h"
        -:   15:#endif
        -:   16:static int MPIDI_CH3I_PMI_Abort(int exit_code, const char *error_msg);
        -:   17:#endif
        -:   18:
        -:   19:/* FIXME: We should move this into a header file so that we don't
        -:   20:   need the ifdef.  Also, don't use exit (add to coding check) since
        -:   21:   not safe in windows.  To avoid confusion, define a RobustExit? or
        -:   22:   MPIU_Exit? */
        -:   23:#ifdef HAVE_WINDOWS_H
        -:   24:/* exit can hang if libc fflushes output while in/out/err buffers are locked
        -:   25:   (this must be a bug in exit?).  ExitProcess does not hang (what does this
        -:   26:   mean about the state of the locked buffers?). */
        -:   27:#define exit(_e) ExitProcess(_e)
        -:   28:#endif
        -:   29:
        -:   30:/* FIXME: This routine *or* MPI_Abort should provide abort callbacks,
        -:   31:   similar to the support in MPI_Finalize */
        -:   32:
        -:   33:#undef FUNCNAME
        -:   34:#define FUNCNAME MPID_Abort
        -:   35:#undef FCNAME
        -:   36:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:   37:int MPID_Abort(MPID_Comm * comm, int mpi_errno, int exit_code, 
        -:   38:	       const char *error_msg)
        6:   39:{
        -:   40:    int rank;
        6:   41:    char msg[MPI_MAX_ERROR_STRING] = "";
        -:   42:    char error_str[MPI_MAX_ERROR_STRING + 100];
        -:   43:    MPIDI_STATE_DECL(MPID_STATE_MPID_ABORT);
        -:   44:
        -:   45:    MPIDI_FUNC_ENTER(MPID_STATE_MPID_ABORT);
        -:   46:
        6:   47:    if (error_msg == NULL) {
        -:   48:	/* Create a default error message */
    #####:   49:	error_msg = error_str;
        -:   50:	/* FIXME: Do we want the rank of the input communicator here 
        -:   51:	   or the rank of comm world?  The message gives the rank but not the 
        -:   52:	   communicator, so using other than the rank in comm world does not 
        -:   53:	   identify the process, as the message suggests */
    #####:   54:	if (comm)
        -:   55:	{
    #####:   56:	    rank = comm->rank;
        -:   57:	}
        -:   58:	else
        -:   59:	{
    #####:   60:	    if (MPIR_Process.comm_world != NULL)
        -:   61:	    {
    #####:   62:		rank = MPIR_Process.comm_world->rank;
        -:   63:	    }
        -:   64:	    else
        -:   65:	    {
    #####:   66:		rank = -1;
        -:   67:	    }
        -:   68:	}
        -:   69:
    #####:   70:	if (mpi_errno != MPI_SUCCESS)
        -:   71:	{
    #####:   72:	    MPIR_Err_get_string(mpi_errno, msg, MPI_MAX_ERROR_STRING, NULL);
        -:   73:	    /* FIXME: Not internationalized */
    #####:   74:	    MPIU_Snprintf(error_str, sizeof(error_str), "internal ABORT - process %d: %s", rank, msg);
        -:   75:	}
        -:   76:	else
        -:   77:	{
        -:   78:	    /* FIXME: Not internationalized */
    #####:   79:	    MPIU_Snprintf(error_str, sizeof(error_str), "internal ABORT - process %d", rank);
        -:   80:	}
        -:   81:    }
        -:   82:    
        -:   83:    MPIDU_Ftb_publish(MPIDU_FTB_EV_ABORT, error_msg);
        -:   84:    MPIDU_Ftb_finalize();
        -:   85:
        -:   86:#ifdef HAVE_DEBUGGER_SUPPORT
        -:   87:    MPIR_DebuggerSetAborting( error_msg );
        -:   88:#endif
        -:   89:
        -:   90:    /* FIXME: This should not use an ifelse chain. Either define the function
        -:   91:       by name or set a function pointer */
        -:   92:#ifdef MPIDI_CH3_IMPLEMENTS_ABORT
        -:   93:    MPIDI_CH3_Abort(exit_code, error_msg);
        -:   94:#elif defined(MPIDI_DEV_IMPLEMENTS_ABORT)
        6:   95:    MPIDI_CH3I_PMI_Abort(exit_code, error_msg);
        -:   96:#else
        -:   97:    MPIU_Error_printf("%s\n", error_msg);
        -:   98:    fflush(stderr);
        -:   99:#endif
        -:  100:
        -:  101:    /* ch3_abort should not return but if it does, exit here.  If it does,
        -:  102:       add the function exit code before calling the final exit.  */
        -:  103:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_ABORT);
    #####:  104:    MPIU_Exit(exit_code);
        -:  105:    
    #####:  106:    return MPI_ERR_INTERN;
        -:  107:}
        -:  108:
        -:  109:#ifdef MPIDI_DEV_IMPLEMENTS_ABORT
        -:  110:#undef FUNCNAME
        -:  111:#define FUNCNAME MPIDI_CH3I_PMI_Abort
        -:  112:#undef FCNAME
        -:  113:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  114:static int MPIDI_CH3I_PMI_Abort(int exit_code, const char *error_msg)
        6:  115:{
        -:  116:    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PMI_ABORT);
        -:  117:    
        -:  118:    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PMI_ABORT);
        -:  119:
        -:  120:    /* Dumping the error message in MPICH2 and passing the same
        -:  121:     * message to the PM as well. This might cause duplicate messages,
        -:  122:     * but it is better to have two messages than none. Note that the
        -:  123:     * PM is in a better position to throw the message (e.g., in case
        -:  124:     * where the stdout/stderr pipes from MPICH2 to the PM are
        -:  125:     * broken), but not all PMs might display respect the message
        -:  126:     * (this problem was noticed with SLURM). */
        6:  127:    MPIU_Error_printf("%s\n", error_msg);
        6:  128:    fflush(stderr);
        -:  129:
        -:  130:    /* FIXME: What is the scope for PMI_Abort?  Shouldn't it be one or more
        -:  131:       process groups?  Shouldn't abort of a communicator abort either the
        -:  132:       process groups of the communicator or only the current process?
        -:  133:       Should PMI_Abort have a parameter for which of these two cases to
        -:  134:       perform? */
        -:  135:#ifdef USE_PMI2_API
        -:  136:    PMI2_Abort(TRUE, error_msg);
        -:  137:#else
        6:  138:    PMI_Abort(exit_code, error_msg);
        -:  139:#endif
        -:  140:
        -:  141:    /* if abort returns for some reason, exit here */
    #####:  142:    exit(exit_code);
        -:  143:
        -:  144:    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PMI_ABORT);
        -:  145:    return MPI_ERR_INTERN;    
        -:  146:}
        -:  147:#endif