This source file includes following definitions.
- ompi_errhandler_init
- ompi_errhandler_finalize
- ompi_errhandler_create
- ompi_errhandler_registration_callback
- ompi_errhandler_callback
- ompi_errhandler_construct
- ompi_errhandler_destruct
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  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 
  40 
  41 opal_pointer_array_t ompi_errhandler_f_to_c_table = {{0}};
  42 
  43 
  44 
  45 
  46 static size_t default_errhandler_id = SIZE_MAX;
  47 
  48 
  49 
  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 
  57 
  58 OBJ_CLASS_INSTANCE(ompi_errhandler_t, opal_object_t, ompi_errhandler_construct,
  59                    ompi_errhandler_destruct);
  60 
  61 
  62 
  63 
  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 
  81 
  82 int ompi_errhandler_init(void)
  83 {
  84   
  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   
  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   
 131 
 132 
 133 
 134 
 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   
 151 
 152   return OMPI_SUCCESS;
 153 }
 154 
 155 
 156 
 157 
 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     
 167 
 168     opal_pmix.deregister_evhandler(default_errhandler_id, NULL, NULL);
 169 
 170     
 171 
 172     OBJ_DESTRUCT(&ompi_errhandler_f_to_c_table);
 173 
 174     
 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   
 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       
 196 
 197 
 198 
 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   
 221 
 222   return new_errhandler;
 223 }
 224 
 225 
 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 
 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     
 247 
 248     if (NULL != cbfunc) {
 249         cbfunc(OMPI_ERR_HANDLERS_COMPLETE, NULL, NULL, NULL, cbdata);
 250     }
 251     
 252     ompi_mpi_abort(MPI_COMM_WORLD, status);
 253 }
 254 
 255 
 256 
 257 
 258 
 259 
 260 
 261 
 262 
 263 
 264 static void ompi_errhandler_construct(ompi_errhandler_t *new_errhandler)
 265 {
 266   int ret_val;
 267 
 268   
 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 
 289 
 290 static void ompi_errhandler_destruct(ompi_errhandler_t *errhandler)
 291 {
 292   
 293 
 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 }