2004-01-12 19:08:46 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-03-20 03:53:55 +03:00
|
|
|
/** @file **/
|
2004-01-12 19:08:46 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#ifndef OMPI_ERRHANDLER_H
|
|
|
|
#define OMPI_ERRHANDLER_H
|
2004-01-12 19:08:46 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-12 19:08:46 +03:00
|
|
|
|
2004-03-19 03:00:09 +03:00
|
|
|
#include "mpi.h"
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "class/ompi_object.h"
|
|
|
|
#include "class/ompi_pointer_array.h"
|
2004-08-08 09:20:32 +04:00
|
|
|
#include "mpi/runtime/mpiruntime.h"
|
2004-06-18 19:47:17 +04:00
|
|
|
#include "errhandler/errhandler_predefined.h"
|
2004-09-06 16:06:27 +04:00
|
|
|
#include "errhandler/errcode-internal.h"
|
2004-03-19 03:00:09 +03:00
|
|
|
|
2004-04-21 02:17:20 +04:00
|
|
|
/*
|
|
|
|
* These must correspond to the fortran handle indices
|
|
|
|
*/
|
2004-06-23 00:21:35 +04:00
|
|
|
enum {
|
|
|
|
OMPI_ERRHANDLER_NULL_FORTRAN = 0,
|
|
|
|
OMPI_ERRORS_ARE_FATAL_FORTRAN,
|
|
|
|
OMPI_ERRORS_RETURN_FORTRAN
|
|
|
|
};
|
2004-03-19 09:12:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Typedef for all fortran errhandler functions
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
typedef void (ompi_errhandler_fortran_handler_fn_t)(int *, int *, ...);
|
2004-03-19 09:12:43 +03:00
|
|
|
|
2004-09-06 16:06:27 +04:00
|
|
|
/**
|
|
|
|
* Typedef for generic errhandler function
|
|
|
|
*/
|
|
|
|
typedef void (ompi_errhandler_generic_handler_fn_t)(void *, int *, ...);
|
|
|
|
|
2004-03-19 09:12:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enum used to describe what kind MPI object an error handler is used for
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
enum ompi_errhandler_type_t {
|
2004-09-06 16:06:27 +04:00
|
|
|
OMPI_ERRHANDLER_TYPE_PREDEFINED,
|
2004-06-07 19:33:53 +04:00
|
|
|
OMPI_ERRHANDLER_TYPE_COMM,
|
|
|
|
OMPI_ERRHANDLER_TYPE_WIN,
|
|
|
|
OMPI_ERRHANDLER_TYPE_FILE
|
2004-03-19 09:12:43 +03:00
|
|
|
};
|
2004-06-07 19:33:53 +04:00
|
|
|
typedef enum ompi_errhandler_type_t ompi_errhandler_type_t;
|
2004-03-19 09:12:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Back-end type for MPI_Errorhandler.
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
struct ompi_errhandler_t {
|
2004-09-06 16:06:27 +04:00
|
|
|
ompi_object_t super;
|
2004-03-19 09:12:43 +03:00
|
|
|
|
2004-09-06 16:06:27 +04:00
|
|
|
char eh_name[MPI_MAX_OBJECT_NAME];
|
|
|
|
/* Type of MPI object that this handler is for */
|
|
|
|
|
|
|
|
ompi_errhandler_type_t eh_mpi_object_type;
|
2004-03-19 09:12:43 +03:00
|
|
|
|
2004-09-06 16:06:27 +04:00
|
|
|
/* Flags about the error handler */
|
|
|
|
bool eh_fortran_function;
|
2004-03-19 09:12:43 +03:00
|
|
|
|
2004-09-06 16:06:27 +04:00
|
|
|
/* Function pointers */
|
|
|
|
MPI_Comm_errhandler_fn *eh_comm_fn;
|
|
|
|
MPI_File_errhandler_fn *eh_file_fn;
|
|
|
|
MPI_Win_errhandler_fn *eh_win_fn;
|
|
|
|
ompi_errhandler_fortran_handler_fn_t *eh_fort_fn;
|
2004-03-19 09:12:43 +03:00
|
|
|
|
2004-09-06 16:06:27 +04:00
|
|
|
/* index in Fortran <-> C translation array */
|
2004-10-20 03:58:12 +04:00
|
|
|
size_t eh_f_to_c_index;
|
2004-01-12 19:08:46 +03:00
|
|
|
};
|
2004-06-07 19:33:53 +04:00
|
|
|
typedef struct ompi_errhandler_t ompi_errhandler_t;
|
2004-01-12 19:08:46 +03:00
|
|
|
|
2004-03-19 03:00:09 +03:00
|
|
|
|
2004-03-19 20:29:39 +03:00
|
|
|
/**
|
|
|
|
* Global variable for MPI_ERRHANDLER_NULL
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
extern ompi_errhandler_t ompi_mpi_errhandler_null;
|
2004-03-19 20:29:39 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Global variable for MPI_ERRORS_ARE_FATAL
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
extern ompi_errhandler_t ompi_mpi_errors_are_fatal;
|
2004-03-19 20:29:39 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Global variable for MPI_ERRORS_RETURN
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
extern ompi_errhandler_t ompi_mpi_errors_return;
|
2004-03-19 20:29:39 +03:00
|
|
|
|
2004-03-19 22:01:09 +03:00
|
|
|
/**
|
|
|
|
* Table for Fortran <-> C errhandler handle conversion
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
extern ompi_pointer_array_t *ompi_errhandler_f_to_c_table;
|
2004-03-19 20:29:39 +03:00
|
|
|
|
|
|
|
|
2004-06-18 19:47:17 +04:00
|
|
|
/**
|
|
|
|
* This is the macro to check the state of MPI and determine whether
|
|
|
|
* it was properly initialized and not yet finalized.
|
|
|
|
*
|
|
|
|
* This macro directly invokes the ompi_mpi_errors_are_fatal_handler()
|
|
|
|
* when an error occurs because MPI_COMM_WORLD does not exist (because
|
|
|
|
* we're before MPI_Init() or after MPI_Finalize()).
|
|
|
|
*/
|
2004-06-23 00:21:35 +04:00
|
|
|
#define OMPI_ERR_INIT_FINALIZE(name) \
|
2004-06-18 19:47:17 +04:00
|
|
|
if (!ompi_mpi_initialized || ompi_mpi_finalized) { \
|
2004-09-06 16:06:27 +04:00
|
|
|
ompi_mpi_errors_are_fatal_comm_handler(NULL, NULL, name); \
|
2004-06-18 19:47:17 +04:00
|
|
|
}
|
|
|
|
|
2004-03-19 03:00:09 +03:00
|
|
|
/**
|
|
|
|
* This is the macro to invoke to directly invoke an MPI error
|
|
|
|
* handler.
|
|
|
|
*
|
|
|
|
* @param mpi_object The MPI object to invoke the errhandler on (a
|
|
|
|
* comm, win, or win)
|
|
|
|
* @param err_code The error code
|
|
|
|
* @param message Any additional message; typically the name of the
|
|
|
|
* MPI function that is invoking the error.
|
|
|
|
*
|
|
|
|
* This macro is used when you want to directly invoke the error
|
|
|
|
* handler. It is exactly equivalent to calling
|
2004-06-07 19:33:53 +04:00
|
|
|
* ompi_errhandler_invoke() directly, but is provided to have a
|
|
|
|
* parallel invocation to OMPI_ERRHANDLER_CHECK() and OMPI_ERRHANDLER_RETURN().
|
2004-03-19 03:00:09 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#define OMPI_ERRHANDLER_INVOKE(mpi_object, err_code, message) \
|
2004-09-16 00:55:29 +04:00
|
|
|
ompi_errhandler_invoke((mpi_object)->error_handler, \
|
2004-09-06 16:06:27 +04:00
|
|
|
(mpi_object), \
|
|
|
|
(int)(mpi_object)->errhandler_type, \
|
|
|
|
(err_code < 0 ? (ompi_errcode_get_mpi_code(err_code)) : err_code), \
|
|
|
|
(message));
|
2004-03-19 03:00:09 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Conditionally invoke an MPI error handler.
|
|
|
|
*
|
|
|
|
* @param rc The return code to check
|
|
|
|
* @param mpi_object The MPI object to invoke the errhandler on (a
|
|
|
|
* comm, win, or win)
|
|
|
|
* @param err_code The error code
|
|
|
|
* @param message Any additional message; typically the name of the
|
|
|
|
* MPI function that is invoking the error.
|
|
|
|
*
|
|
|
|
* This macro will invoke the error handler if the return code is not
|
2004-06-07 19:33:53 +04:00
|
|
|
* OMPI_SUCCESS.
|
2004-03-19 03:00:09 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#define OMPI_ERRHANDLER_CHECK(rc, mpi_object, err_code, message) \
|
|
|
|
if (rc != OMPI_SUCCESS) { \
|
2004-09-06 16:06:27 +04:00
|
|
|
int __mpi_err_code = (err_code < 0 ? (ompi_errcode_get_mpi_code(err_code)) : err_code); \
|
2004-09-16 00:55:29 +04:00
|
|
|
ompi_errhandler_invoke((mpi_object)->error_handler, \
|
2004-09-06 16:06:27 +04:00
|
|
|
(mpi_object), \
|
|
|
|
(int) (mpi_object)->errhandler_type, \
|
|
|
|
(__mpi_err_code), \
|
|
|
|
(message)); \
|
|
|
|
return (__mpi_err_code); \
|
2004-03-19 03:00:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Conditionally invoke an MPI error handler; if there is no error,
|
|
|
|
* return MPI_SUCCESS.
|
|
|
|
*
|
|
|
|
* @param rc The return code to check
|
|
|
|
* @param mpi_object The MPI object to invoke the errhandler on (a
|
|
|
|
* comm, win, or win)
|
|
|
|
* @param err_code The error code
|
|
|
|
* @param message Any additional message; typically the name of the
|
|
|
|
* MPI function that is invoking the error.
|
|
|
|
*
|
|
|
|
* This macro will invoke the error handler if the return code is not
|
2004-06-07 19:33:53 +04:00
|
|
|
* OMPI_SUCCESS. If the return code is OMPI_SUCCESS, then return
|
2004-03-19 03:00:09 +03:00
|
|
|
* MPI_SUCCESS.
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#define OMPI_ERRHANDLER_RETURN(rc, mpi_object, err_code, message) \
|
|
|
|
if (rc != OMPI_SUCCESS) { \
|
2004-09-06 16:06:27 +04:00
|
|
|
int __mpi_err_code = (err_code < 0 ? (ompi_errcode_get_mpi_code(err_code)) : err_code); \
|
2004-09-16 00:55:29 +04:00
|
|
|
ompi_errhandler_invoke((mpi_object)->error_handler, \
|
2004-09-06 16:06:27 +04:00
|
|
|
(mpi_object), \
|
|
|
|
(int)(mpi_object)->errhandler_type, \
|
|
|
|
(__mpi_err_code), \
|
|
|
|
(message)); \
|
|
|
|
return (__mpi_err_code); \
|
2004-03-19 03:00:09 +03:00
|
|
|
} else { \
|
|
|
|
return MPI_SUCCESS; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-19 09:12:43 +03:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the error handler interface.
|
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* @returns OMPI_SUCCESS Upon success
|
|
|
|
* @returns OMPI_ERROR Otherwise
|
2004-03-20 03:53:55 +03:00
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* Invoked from ompi_mpi_init(); sets up the error handler interface,
|
2004-03-19 09:12:43 +03:00
|
|
|
* creates the predefined MPI errorhandlers, and creates the
|
|
|
|
* corresopnding F2C translation table.
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_errhandler_init(void);
|
2004-03-19 09:12:43 +03:00
|
|
|
|
2004-03-20 03:53:55 +03:00
|
|
|
/**
|
2004-03-19 09:12:43 +03:00
|
|
|
* Finalize the error handler interface.
|
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* @returns OMPI_SUCCESS Always
|
2004-03-20 03:53:55 +03:00
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* Invokes from ompi_mpi_finalize(); tears down the error handler
|
2004-03-19 09:12:43 +03:00
|
|
|
* interface, and destroys the F2C translation table.
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_errhandler_finalize(void);
|
2004-03-19 09:12:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* This function should not be invoked directly; it should only be
|
2004-06-07 19:33:53 +04:00
|
|
|
* invoked by OMPI_ERRHANDLER_INVOKE(), OMPI_ERRHANDLER_CHECK(), or
|
|
|
|
* OMPI_ERRHANDLER_RETURN().
|
2004-03-19 09:12:43 +03:00
|
|
|
*
|
|
|
|
* @param errhandler The MPI_Errhandler to invoke
|
|
|
|
* @param mpi_object The MPI object to invoke the errhandler on (a
|
|
|
|
* comm, win, or win)
|
2004-09-06 16:06:27 +04:00
|
|
|
* @param type The type of the MPI object. Necessary, since
|
|
|
|
* you can not assign a single type to the predefined
|
|
|
|
* error handlers. This information is therefore
|
|
|
|
* stored on the MPI object itself.
|
2004-03-19 09:12:43 +03:00
|
|
|
* @param err_code The error code
|
|
|
|
* @param message Any additional message; typically the name of the
|
|
|
|
* MPI function that is invoking the error.
|
|
|
|
*
|
2004-03-20 03:53:55 +03:00
|
|
|
* @returns err_code The same value as the parameter
|
|
|
|
*
|
2004-03-19 09:12:43 +03:00
|
|
|
* This function invokes the MPI exception function on the error
|
|
|
|
* handler. If the errhandler was created from fortran, the error
|
|
|
|
* handler will be invoked with fortran linkage. Otherwise, it is
|
|
|
|
* invoked with C linkage.
|
2004-03-20 03:53:55 +03:00
|
|
|
*
|
|
|
|
* If this function returns, it returns the err_code. Note that it
|
|
|
|
* may not return (e.g., for MPI_ERRORS_ARE_FATAL).
|
2004-03-19 09:12:43 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_errhandler_invoke(ompi_errhandler_t *errhandler, void *mpi_object,
|
2004-09-06 16:06:27 +04:00
|
|
|
int type, int err_code, const char *message);
|
2004-03-19 09:12:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2004-06-07 19:33:53 +04:00
|
|
|
* Create a ompi_errhandler_t
|
2004-03-19 20:29:39 +03:00
|
|
|
*
|
|
|
|
* @param object_type Enum of the type of MPI object
|
|
|
|
* @param func Function pointer of the error handler
|
2004-03-20 03:53:55 +03:00
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* @returns errhandler Pointer to the ompi_errorhandler_t that will be
|
2004-03-19 20:29:39 +03:00
|
|
|
* created and returned
|
|
|
|
*
|
2004-03-20 03:53:55 +03:00
|
|
|
* This function is called as the back-end of all the
|
|
|
|
* MPI_*_CREATE_ERRHANDLER functions. It creates a new
|
2004-06-07 19:33:53 +04:00
|
|
|
* ompi_errhandler_t object, initializes it to the correct object
|
2004-03-20 03:53:55 +03:00
|
|
|
* type, and sets the callback function on it.
|
|
|
|
*
|
|
|
|
* The type of the function pointer is (arbitrarily) the fortran
|
|
|
|
* function handler type. Since this function has to accept 4
|
|
|
|
* different function pointer types (lest we have 4 different
|
|
|
|
* functions to create errhandlers), the fortran one was picked
|
|
|
|
* arbitrarily. Note that (void*) is not sufficient because at
|
|
|
|
* least theoretically, a sizeof(void*) may not necessarily be the
|
|
|
|
* same as sizeof(void(*)).
|
|
|
|
*
|
|
|
|
* NOTE: It *always* sets the "fortran" flag to false. Fortran
|
|
|
|
* wrappers for MPI_*_CREATE_ERRHANDLER are expected to reset this
|
2004-04-21 03:10:44 +04:00
|
|
|
* flag to true manually.
|
2004-03-19 09:12:43 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_errhandler_t *ompi_errhandler_create(ompi_errhandler_type_t object_type,
|
2004-09-06 16:06:27 +04:00
|
|
|
ompi_errhandler_generic_handler_fn_t *func);
|
2004-03-19 09:12:43 +03:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-19 21:01:03 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if an errhandler is intrinsic.
|
|
|
|
*
|
|
|
|
* @param errhandler The errhandler to check
|
|
|
|
*
|
|
|
|
* @returns true If the errhandler is intrinsic
|
|
|
|
* @returns false If the errhandler is not intrinsic
|
2004-03-20 03:53:55 +03:00
|
|
|
*
|
|
|
|
* Self-explanitory. This is needed in a few top-level MPI functions;
|
|
|
|
* this function is provided to hide the internal structure field
|
|
|
|
* names.
|
2004-03-19 21:01:03 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
static inline bool ompi_errhandler_is_intrinsic(ompi_errhandler_t *errhandler)
|
2004-03-19 21:01:03 +03:00
|
|
|
{
|
2004-09-06 16:06:27 +04:00
|
|
|
if ( OMPI_ERRHANDLER_TYPE_PREDEFINED == errhandler->eh_mpi_object_type )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2004-03-19 21:01:03 +03:00
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#endif /* OMPI_ERRHANDLER_H */
|