1
1
openmpi/ompi/errhandler/errhandler.c
Ralph Castain e4e678e234 Per the RFC and discussion on the devel list, update the RTE-MPI error handling interface. There are a few differences in the code from the original RFC that came out of the discussion - I've captured those in the following writeup
George and I were talking about ORTE's error handling the other day in regards to the right way to deal with errors in the updated OOB. Specifically, it seemed a bad idea for a library such as ORTE to be aborting the job on its own prerogative. If we lose a connection or cannot send a message, then we really should just report it upwards and let the application and/or upper layers decide what to do about it.

The current code base only allows a single error callback to exist, which seemed unduly limiting. So, based on the conversation, I've modified the errmgr interface to provide a mechanism for registering any number of error handlers (this replaces the current "set_fault_callback" API). When an error occurs, these handlers will be called in order until one responds that the error has been "resolved" - i.e., no further action is required - by returning OMPI_SUCCESS. The default MPI layer error handler is specified to go "last" and calls mpi_abort, so the current "abort" behavior is preserved unless other error handlers are registered.

In the register_callback function, I provide an "order" param so you can specify "this callback must come first" or "this callback must come last". Seemed to me that we will probably have different code areas registering callbacks, and one might require it go first (the default "abort" will always require it go last). So you can append and prepend, or go first. Note that only one registration can declare itself "first" or "last", and since the default "abort" callback automatically takes "last", that one isn't available. :-)

The errhandler callback function passes an opal_pointer_array of structs, each of which contains the name of the proc involved (which can be yourself for internal errors) and the error code. This is a change from the current fault callback which returned an opal_pointer_array of just process names. Rationale is that you might need to see the cause of the error to decide what action to take. I realize that isn't a requirement for remote procs, but remember that we will use the SAME interface to report RTE errors internal to the proc itself. In those cases, you really do need to see the error code. It is legal to pass a NULL for the pointer array (e.g., when reporting an internal failure without error code), so handlers must be prepared for that possibility. If people find that too burdensome, we can remove it.

Should we ever decide to create a separate callback path for internal errors vs remote process failures, or if we decide to do something different based on experience, then we can adjust this API.

This commit was SVN r28852.
2013-07-19 01:08:53 +00:00

278 строки
9.4 KiB
C

/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2011 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "ompi/communicator/communicator.h"
#include "ompi/win/win.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/errhandler/errhandler_predefined.h"
#include "opal/class/opal_pointer_array.h"
/*
* Table for Fortran <-> C errhandler handle conversion
*/
opal_pointer_array_t ompi_errhandler_f_to_c_table;
/*
* Class information
*/
static void ompi_errhandler_construct(ompi_errhandler_t *eh);
static void ompi_errhandler_destruct(ompi_errhandler_t *eh);
/*
* Class instance
*/
OBJ_CLASS_INSTANCE(ompi_errhandler_t, opal_object_t, ompi_errhandler_construct,
ompi_errhandler_destruct);
/*
* _addr flavors are for F03 bindings
*/
ompi_predefined_errhandler_t ompi_mpi_errhandler_null;
ompi_predefined_errhandler_t *ompi_mpi_errhandler_null_addr =
&ompi_mpi_errhandler_null;
ompi_predefined_errhandler_t ompi_mpi_errors_are_fatal;
ompi_predefined_errhandler_t *ompi_mpi_errors_are_fatal_addr =
&ompi_mpi_errors_are_fatal;
ompi_predefined_errhandler_t ompi_mpi_errors_return;
ompi_predefined_errhandler_t *ompi_mpi_errors_return_addr =
&ompi_mpi_errors_return;
ompi_predefined_errhandler_t ompi_mpi_errors_throw_exceptions;
ompi_predefined_errhandler_t *ompi_mpi_errors_throw_exceptions_addr =
&ompi_mpi_errors_throw_exceptions;
/*
* Initialize OMPI errhandler infrastructure
*/
int ompi_errhandler_init(void)
{
/* initialize ompi_errhandler_f_to_c_table */
OBJ_CONSTRUCT( &ompi_errhandler_f_to_c_table, opal_pointer_array_t);
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_errhandler_f_to_c_table, 0,
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
return OMPI_ERROR;
}
/* Initialize the predefined error handlers */
OBJ_CONSTRUCT( &ompi_mpi_errhandler_null.eh, ompi_errhandler_t );
if( ompi_mpi_errhandler_null.eh.eh_f_to_c_index != OMPI_ERRHANDLER_NULL_FORTRAN )
return OMPI_ERROR;
ompi_mpi_errhandler_null.eh.eh_mpi_object_type = OMPI_ERRHANDLER_TYPE_PREDEFINED;
ompi_mpi_errhandler_null.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
ompi_mpi_errhandler_null.eh.eh_comm_fn = NULL;
ompi_mpi_errhandler_null.eh.eh_file_fn = NULL;
ompi_mpi_errhandler_null.eh.eh_win_fn = NULL ;
ompi_mpi_errhandler_null.eh.eh_fort_fn = NULL;
strncpy (ompi_mpi_errhandler_null.eh.eh_name, "MPI_ERRHANDLER_NULL",
strlen("MPI_ERRHANDLER_NULL")+1 );
OBJ_CONSTRUCT( &ompi_mpi_errors_are_fatal.eh, ompi_errhandler_t );
if( ompi_mpi_errors_are_fatal.eh.eh_f_to_c_index != OMPI_ERRORS_ARE_FATAL_FORTRAN )
return OMPI_ERROR;
ompi_mpi_errors_are_fatal.eh.eh_mpi_object_type = OMPI_ERRHANDLER_TYPE_PREDEFINED;
ompi_mpi_errors_are_fatal.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
ompi_mpi_errors_are_fatal.eh.eh_comm_fn = ompi_mpi_errors_are_fatal_comm_handler;
ompi_mpi_errors_are_fatal.eh.eh_file_fn = ompi_mpi_errors_are_fatal_file_handler;
ompi_mpi_errors_are_fatal.eh.eh_win_fn = ompi_mpi_errors_are_fatal_win_handler ;
ompi_mpi_errors_are_fatal.eh.eh_fort_fn = NULL;
strncpy (ompi_mpi_errors_are_fatal.eh.eh_name, "MPI_ERRORS_ARE_FATAL",
strlen("MPI_ERRORS_ARE_FATAL")+1 );
OBJ_CONSTRUCT( &ompi_mpi_errors_return.eh, ompi_errhandler_t );
if( ompi_mpi_errors_return.eh.eh_f_to_c_index != OMPI_ERRORS_RETURN_FORTRAN )
return OMPI_ERROR;
ompi_mpi_errors_return.eh.eh_mpi_object_type = OMPI_ERRHANDLER_TYPE_PREDEFINED;
ompi_mpi_errors_return.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
ompi_mpi_errors_return.eh.eh_comm_fn = ompi_mpi_errors_return_comm_handler;
ompi_mpi_errors_return.eh.eh_file_fn = ompi_mpi_errors_return_file_handler;
ompi_mpi_errors_return.eh.eh_win_fn = ompi_mpi_errors_return_win_handler;
ompi_mpi_errors_return.eh.eh_fort_fn = NULL;
strncpy (ompi_mpi_errors_return.eh.eh_name, "MPI_ERRORS_RETURN",
strlen("MPI_ERRORS_RETURN")+1 );
/* If we're going to use C++, functions will be fixed up during
MPI::Init. Note that it is proper to use ERRHANDLER_LANG_C here;
the dispatch function is in C (although in libmpi_cxx); the
conversion from C handles to C++ handles happens in that dispatch
function -- not the errhandler_invoke.c stuff here in libmpi. */
OBJ_CONSTRUCT( &ompi_mpi_errors_throw_exceptions.eh, ompi_errhandler_t );
ompi_mpi_errors_throw_exceptions.eh.eh_mpi_object_type =
OMPI_ERRHANDLER_TYPE_PREDEFINED;
ompi_mpi_errors_throw_exceptions.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
ompi_mpi_errors_throw_exceptions.eh.eh_comm_fn =
ompi_mpi_errors_are_fatal_comm_handler;
ompi_mpi_errors_throw_exceptions.eh.eh_file_fn =
ompi_mpi_errors_are_fatal_file_handler;
ompi_mpi_errors_throw_exceptions.eh.eh_win_fn =
ompi_mpi_errors_are_fatal_win_handler ;
ompi_mpi_errors_throw_exceptions.eh.eh_fort_fn = NULL;
strncpy (ompi_mpi_errors_throw_exceptions.eh.eh_name, "MPI_ERRORS_THROW_EXCEPTIONS",
strlen("MPI_ERRORS_THROW_EXCEPTIONS")+1 );
/* All done */
return OMPI_SUCCESS;
}
/*
* Clean up the errorhandler resources
*/
int ompi_errhandler_finalize(void)
{
OBJ_DESTRUCT(&ompi_mpi_errhandler_null.eh);
OBJ_DESTRUCT(&ompi_mpi_errors_return.eh);
OBJ_DESTRUCT(&ompi_mpi_errors_throw_exceptions.eh);
OBJ_DESTRUCT(&ompi_mpi_errors_are_fatal.eh);
/* JMS Add stuff here checking for unreleased errorhandlers,
similar to communicators, info handles, etc. */
/* Remove errhandler F2C table */
OBJ_DESTRUCT(&ompi_errhandler_f_to_c_table);
/* All done */
return OMPI_SUCCESS;
}
ompi_errhandler_t *ompi_errhandler_create(ompi_errhandler_type_t object_type,
ompi_errhandler_generic_handler_fn_t *func,
ompi_errhandler_lang_t lang)
{
ompi_errhandler_t *new_errhandler;
/* Create a new object and ensure that it's valid */
new_errhandler = OBJ_NEW(ompi_errhandler_t);
if (NULL != new_errhandler) {
if (0 > new_errhandler->eh_f_to_c_index) {
OBJ_RELEASE(new_errhandler);
new_errhandler = NULL;
} else {
/* We cast the user's callback function to any one of the
function pointer types in the union; it doesn't matter which.
It only matters that we dereference/use the right member when
invoking the callback. */
new_errhandler->eh_mpi_object_type = object_type;
new_errhandler->eh_lang = lang;
switch (object_type ) {
case (OMPI_ERRHANDLER_TYPE_COMM):
new_errhandler->eh_comm_fn = (MPI_Comm_errhandler_function *)func;
break;
case (OMPI_ERRHANDLER_TYPE_FILE):
new_errhandler->eh_file_fn = (ompi_file_errhandler_fn *)func;
break;
case (OMPI_ERRHANDLER_TYPE_WIN):
new_errhandler->eh_win_fn = (MPI_Win_errhandler_function *)func;
break;
default:
break;
}
new_errhandler->eh_fort_fn = (ompi_errhandler_fortran_handler_fn_t *)func;
}
}
/* All done */
return new_errhandler;
}
/**
* Default runtime errhandler callback
*/
int ompi_errhandler_runtime_callback(opal_pointer_array_t *errors) {
ompi_rte_error_report_t *err;
int errcode = 1;
if (NULL != errors ||
(NULL != (err = (ompi_rte_error_report_t*)opal_pointer_array_get_item(errors, 0)))) {
errcode = err->errcode;
}
ompi_mpi_abort(MPI_COMM_WORLD, errcode, false);
return OMPI_SUCCESS;
}
/**************************************************************************
*
* Static functions
*
**************************************************************************/
/**
* Errhandler constructor
*/
static void ompi_errhandler_construct(ompi_errhandler_t *new_errhandler)
{
int ret_val;
/* assign entry in fortran <-> c translation array */
ret_val = opal_pointer_array_add(&ompi_errhandler_f_to_c_table,
new_errhandler);
new_errhandler->eh_f_to_c_index = ret_val;
new_errhandler->eh_lang = OMPI_ERRHANDLER_LANG_C;
new_errhandler->eh_comm_fn = NULL;
new_errhandler->eh_win_fn = NULL;
new_errhandler->eh_file_fn = NULL;
new_errhandler->eh_fort_fn = NULL;
new_errhandler->eh_cxx_dispatch_fn = NULL;
memset (new_errhandler->eh_name, 0, MPI_MAX_OBJECT_NAME);
}
/**
* Errhandler destructor
*/
static void ompi_errhandler_destruct(ompi_errhandler_t *errhandler)
{
/* reset the ompi_errhandler_f_to_c_table entry - make sure that the
entry is in the table */
if (NULL!= opal_pointer_array_get_item(&ompi_errhandler_f_to_c_table,
errhandler->eh_f_to_c_index)) {
opal_pointer_array_set_item(&ompi_errhandler_f_to_c_table,
errhandler->eh_f_to_c_index, NULL);
}
}