root/ompi/errhandler/errhandler.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ompi_errhandler_init
  2. ompi_errhandler_finalize
  3. ompi_errhandler_create
  4. ompi_errhandler_registration_callback
  5. ompi_errhandler_callback
  6. ompi_errhandler_construct
  7. ompi_errhandler_destruct

   1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2017 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2008-2018 Cisco Systems, Inc.  All rights reserved
  14  * Copyright (c) 2009      Sun Microsystems, Inc.  All rights reserved.
  15  * Copyright (c) 2015      Research Organization for Information Science
  16  *                         and Technology (RIST). All rights reserved.
  17  * Copyright (c) 2015-2016 Intel, Inc. All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  */
  24 
  25 #include "ompi_config.h"
  26 
  27 #include <string.h>
  28 
  29 #include "ompi/communicator/communicator.h"
  30 #include "ompi/win/win.h"
  31 #include "ompi/errhandler/errhandler.h"
  32 #include "ompi/errhandler/errhandler_predefined.h"
  33 #include "opal/class/opal_pointer_array.h"
  34 #include "opal/mca/pmix/pmix.h"
  35 #include "opal/util/string_copy.h"
  36 
  37 
  38 /*
  39  * Table for Fortran <-> C errhandler handle conversion
  40  */
  41 opal_pointer_array_t ompi_errhandler_f_to_c_table = {{0}};
  42 
  43 /*
  44  * default errhandler id
  45  */
  46 static size_t default_errhandler_id = SIZE_MAX;
  47 
  48 /*
  49  * Class information
  50  */
  51 static void ompi_errhandler_construct(ompi_errhandler_t *eh);
  52 static void ompi_errhandler_destruct(ompi_errhandler_t *eh);
  53 
  54 
  55 /*
  56  * Class instance
  57  */
  58 OBJ_CLASS_INSTANCE(ompi_errhandler_t, opal_object_t, ompi_errhandler_construct,
  59                    ompi_errhandler_destruct);
  60 
  61 
  62 /*
  63  * _addr flavors are for F03 bindings
  64  */
  65 ompi_predefined_errhandler_t ompi_mpi_errhandler_null = {{{0}}};
  66 ompi_predefined_errhandler_t *ompi_mpi_errhandler_null_addr =
  67     &ompi_mpi_errhandler_null;
  68 ompi_predefined_errhandler_t ompi_mpi_errors_are_fatal = {{{0}}};
  69 ompi_predefined_errhandler_t *ompi_mpi_errors_are_fatal_addr =
  70     &ompi_mpi_errors_are_fatal;
  71 ompi_predefined_errhandler_t ompi_mpi_errors_return = {{{0}}};
  72 ompi_predefined_errhandler_t *ompi_mpi_errors_return_addr =
  73     &ompi_mpi_errors_return;
  74 ompi_predefined_errhandler_t ompi_mpi_errors_throw_exceptions = {{{0}}};
  75 ompi_predefined_errhandler_t *ompi_mpi_errors_throw_exceptions_addr =
  76     &ompi_mpi_errors_throw_exceptions;
  77 
  78 
  79 /*
  80  * Initialize OMPI errhandler infrastructure
  81  */
  82 int ompi_errhandler_init(void)
  83 {
  84   /* initialize ompi_errhandler_f_to_c_table */
  85 
  86   OBJ_CONSTRUCT( &ompi_errhandler_f_to_c_table, opal_pointer_array_t);
  87   if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_errhandler_f_to_c_table, 8,
  88                                               OMPI_FORTRAN_HANDLE_MAX, 16) ) {
  89     return OMPI_ERROR;
  90   }
  91 
  92   /* Initialize the predefined error handlers */
  93   OBJ_CONSTRUCT( &ompi_mpi_errhandler_null.eh, ompi_errhandler_t );
  94   if( ompi_mpi_errhandler_null.eh.eh_f_to_c_index != OMPI_ERRHANDLER_NULL_FORTRAN )
  95       return OMPI_ERROR;
  96   ompi_mpi_errhandler_null.eh.eh_mpi_object_type = OMPI_ERRHANDLER_TYPE_PREDEFINED;
  97   ompi_mpi_errhandler_null.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
  98   ompi_mpi_errhandler_null.eh.eh_comm_fn = NULL;
  99   ompi_mpi_errhandler_null.eh.eh_file_fn = NULL;
 100   ompi_mpi_errhandler_null.eh.eh_win_fn  = NULL ;
 101   ompi_mpi_errhandler_null.eh.eh_fort_fn = NULL;
 102   opal_string_copy(ompi_mpi_errhandler_null.eh.eh_name, "MPI_ERRHANDLER_NULL",
 103                    sizeof(ompi_mpi_errhandler_null.eh.eh_name));
 104 
 105   OBJ_CONSTRUCT( &ompi_mpi_errors_are_fatal.eh, ompi_errhandler_t );
 106   if( ompi_mpi_errors_are_fatal.eh.eh_f_to_c_index != OMPI_ERRORS_ARE_FATAL_FORTRAN )
 107       return OMPI_ERROR;
 108   ompi_mpi_errors_are_fatal.eh.eh_mpi_object_type = OMPI_ERRHANDLER_TYPE_PREDEFINED;
 109   ompi_mpi_errors_are_fatal.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
 110   ompi_mpi_errors_are_fatal.eh.eh_comm_fn = ompi_mpi_errors_are_fatal_comm_handler;
 111   ompi_mpi_errors_are_fatal.eh.eh_file_fn = ompi_mpi_errors_are_fatal_file_handler;
 112   ompi_mpi_errors_are_fatal.eh.eh_win_fn  = ompi_mpi_errors_are_fatal_win_handler ;
 113   ompi_mpi_errors_are_fatal.eh.eh_fort_fn = NULL;
 114   opal_string_copy(ompi_mpi_errors_are_fatal.eh.eh_name,
 115                    "MPI_ERRORS_ARE_FATAL",
 116                    sizeof(ompi_mpi_errors_are_fatal.eh.eh_name));
 117 
 118   OBJ_CONSTRUCT( &ompi_mpi_errors_return.eh, ompi_errhandler_t );
 119   if( ompi_mpi_errors_return.eh.eh_f_to_c_index != OMPI_ERRORS_RETURN_FORTRAN )
 120       return OMPI_ERROR;
 121   ompi_mpi_errors_return.eh.eh_mpi_object_type  = OMPI_ERRHANDLER_TYPE_PREDEFINED;
 122   ompi_mpi_errors_return.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
 123   ompi_mpi_errors_return.eh.eh_comm_fn = ompi_mpi_errors_return_comm_handler;
 124   ompi_mpi_errors_return.eh.eh_file_fn = ompi_mpi_errors_return_file_handler;
 125   ompi_mpi_errors_return.eh.eh_win_fn  = ompi_mpi_errors_return_win_handler;
 126   ompi_mpi_errors_return.eh.eh_fort_fn = NULL;
 127   opal_string_copy(ompi_mpi_errors_return.eh.eh_name, "MPI_ERRORS_RETURN",
 128                    sizeof(ompi_mpi_errors_return.eh.eh_name));
 129 
 130   /* If we're going to use C++, functions will be fixed up during
 131      MPI::Init.  Note that it is proper to use ERRHANDLER_LANG_C here;
 132      the dispatch function is in C (although in libmpi_cxx); the
 133      conversion from C handles to C++ handles happens in that dispatch
 134      function -- not the errhandler_invoke.c stuff here in libmpi. */
 135   OBJ_CONSTRUCT( &ompi_mpi_errors_throw_exceptions.eh, ompi_errhandler_t );
 136   ompi_mpi_errors_throw_exceptions.eh.eh_mpi_object_type =
 137       OMPI_ERRHANDLER_TYPE_PREDEFINED;
 138   ompi_mpi_errors_throw_exceptions.eh.eh_lang = OMPI_ERRHANDLER_LANG_C;
 139   ompi_mpi_errors_throw_exceptions.eh.eh_comm_fn =
 140       ompi_mpi_errors_are_fatal_comm_handler;
 141   ompi_mpi_errors_throw_exceptions.eh.eh_file_fn =
 142       ompi_mpi_errors_are_fatal_file_handler;
 143   ompi_mpi_errors_throw_exceptions.eh.eh_win_fn  =
 144       ompi_mpi_errors_are_fatal_win_handler ;
 145   ompi_mpi_errors_throw_exceptions.eh.eh_fort_fn = NULL;
 146   opal_string_copy(ompi_mpi_errors_throw_exceptions.eh.eh_name,
 147                    "MPI_ERRORS_THROW_EXCEPTIONS",
 148                    sizeof(ompi_mpi_errors_throw_exceptions.eh.eh_name));
 149 
 150   /* All done */
 151 
 152   return OMPI_SUCCESS;
 153 }
 154 
 155 
 156 /*
 157  * Clean up the errorhandler resources
 158  */
 159 int ompi_errhandler_finalize(void)
 160 {
 161     OBJ_DESTRUCT(&ompi_mpi_errhandler_null.eh);
 162     OBJ_DESTRUCT(&ompi_mpi_errors_return.eh);
 163     OBJ_DESTRUCT(&ompi_mpi_errors_throw_exceptions.eh);
 164     OBJ_DESTRUCT(&ompi_mpi_errors_are_fatal.eh);
 165 
 166     /* JMS Add stuff here checking for unreleased errorhandlers,
 167        similar to communicators, info handles, etc. */
 168     opal_pmix.deregister_evhandler(default_errhandler_id, NULL, NULL);
 169 
 170     /* Remove errhandler F2C table */
 171 
 172     OBJ_DESTRUCT(&ompi_errhandler_f_to_c_table);
 173 
 174     /* All done */
 175 
 176     return OMPI_SUCCESS;
 177 }
 178 
 179 
 180 ompi_errhandler_t *ompi_errhandler_create(ompi_errhandler_type_t object_type,
 181                                                               ompi_errhandler_generic_handler_fn_t *func,
 182                                           ompi_errhandler_lang_t lang)
 183 {
 184   ompi_errhandler_t *new_errhandler;
 185 
 186   /* Create a new object and ensure that it's valid */
 187 
 188   new_errhandler = OBJ_NEW(ompi_errhandler_t);
 189   if (NULL != new_errhandler) {
 190     if (0 > new_errhandler->eh_f_to_c_index) {
 191       OBJ_RELEASE(new_errhandler);
 192       new_errhandler = NULL;
 193     } else {
 194 
 195       /* We cast the user's callback function to any one of the
 196          function pointer types in the union; it doesn't matter which.
 197          It only matters that we dereference/use the right member when
 198          invoking the callback. */
 199 
 200       new_errhandler->eh_mpi_object_type = object_type;
 201       new_errhandler->eh_lang = lang;
 202       switch (object_type ) {
 203           case (OMPI_ERRHANDLER_TYPE_COMM):
 204               new_errhandler->eh_comm_fn = (MPI_Comm_errhandler_function *)func;
 205               break;
 206           case (OMPI_ERRHANDLER_TYPE_FILE):
 207               new_errhandler->eh_file_fn = (ompi_file_errhandler_function *)func;
 208               break;
 209           case (OMPI_ERRHANDLER_TYPE_WIN):
 210               new_errhandler->eh_win_fn = (MPI_Win_errhandler_function *)func;
 211               break;
 212           default:
 213               break;
 214       }
 215 
 216       new_errhandler->eh_fort_fn = (ompi_errhandler_fortran_handler_fn_t *)func;
 217     }
 218   }
 219 
 220   /* All done */
 221 
 222   return new_errhandler;
 223 }
 224 
 225 /* registration callback */
 226 void ompi_errhandler_registration_callback(int status,
 227                                            size_t errhandler_ref,
 228                                            void *cbdata)
 229 {
 230     ompi_errhandler_errtrk_t *errtrk = (ompi_errhandler_errtrk_t*)cbdata;
 231 
 232     default_errhandler_id = errhandler_ref;
 233     errtrk->status = status;
 234     errtrk->active = false;
 235 }
 236 
 237 /**
 238  * Default errhandler callback
 239  */
 240 void ompi_errhandler_callback(int status,
 241                               const opal_process_name_t *source,
 242                               opal_list_t *info, opal_list_t *results,
 243                               opal_pmix_notification_complete_fn_t cbfunc,
 244                               void *cbdata)
 245 {
 246     /* tell the event chain engine to go no further - we
 247      * will handle this */
 248     if (NULL != cbfunc) {
 249         cbfunc(OMPI_ERR_HANDLERS_COMPLETE, NULL, NULL, NULL, cbdata);
 250     }
 251     /* our default action is to abort */
 252     ompi_mpi_abort(MPI_COMM_WORLD, status);
 253 }
 254 
 255 /**************************************************************************
 256  *
 257  * Static functions
 258  *
 259  **************************************************************************/
 260 
 261 /**
 262  * Errhandler constructor
 263  */
 264 static void ompi_errhandler_construct(ompi_errhandler_t *new_errhandler)
 265 {
 266   int ret_val;
 267 
 268   /* assign entry in fortran <-> c translation array */
 269 
 270   ret_val = opal_pointer_array_add(&ompi_errhandler_f_to_c_table,
 271                                    new_errhandler);
 272   new_errhandler->eh_f_to_c_index = ret_val;
 273 
 274   new_errhandler->eh_lang = OMPI_ERRHANDLER_LANG_C;
 275 
 276   new_errhandler->eh_comm_fn      = NULL;
 277   new_errhandler->eh_win_fn       = NULL;
 278   new_errhandler->eh_file_fn      = NULL;
 279   new_errhandler->eh_fort_fn      = NULL;
 280 
 281   new_errhandler->eh_cxx_dispatch_fn = NULL;
 282 
 283   memset (new_errhandler->eh_name, 0, MPI_MAX_OBJECT_NAME);
 284 }
 285 
 286 
 287 /**
 288  * Errhandler destructor
 289  */
 290 static void ompi_errhandler_destruct(ompi_errhandler_t *errhandler)
 291 {
 292   /* reset the ompi_errhandler_f_to_c_table entry - make sure that the
 293      entry is in the table */
 294 
 295   if (NULL!= opal_pointer_array_get_item(&ompi_errhandler_f_to_c_table,
 296                                         errhandler->eh_f_to_c_index)) {
 297     opal_pointer_array_set_item(&ompi_errhandler_f_to_c_table,
 298                                 errhandler->eh_f_to_c_index, NULL);
 299   }
 300 }

/* [<][>][^][v][top][bottom][index][help] */