| 
 | 1 | +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */  | 
 | 2 | +/*  | 
 | 3 | + * Copyright (c) 2016      Los Alamos National Security, LLC.  All rights  | 
 | 4 | + *                         reserved.  | 
 | 5 | + * $COPYRIGHT$  | 
 | 6 | + *  | 
 | 7 | + * Additional copyrights may follow  | 
 | 8 | + *  | 
 | 9 | + * $HEADER$  | 
 | 10 | + */  | 
 | 11 | + | 
 | 12 | +#include "ompi_config.h"  | 
 | 13 | + | 
 | 14 | +#include "ompi/communicator/communicator.h"  | 
 | 15 | +#include "ompi/attribute/attribute.h"  | 
 | 16 | +#include "ompi/errhandler/errhandler.h"  | 
 | 17 | +#include "ompi/file/file.h"  | 
 | 18 | +#include "opal/class/opal_list.h"  | 
 | 19 | +#include "cxx_glue.h"  | 
 | 20 | + | 
 | 21 | +typedef struct ompi_cxx_intercept_file_extra_state_item_t {  | 
 | 22 | +    opal_list_item_t super;  | 
 | 23 | +    ompi_cxx_intercept_file_extra_state_t state;  | 
 | 24 | +} ompi_cxx_intercept_file_extra_state_item_t;  | 
 | 25 | + | 
 | 26 | +OBJ_CLASS_DECLARATION(ompi_cxx_intercept_file_extra_state_item_t);  | 
 | 27 | +OBJ_CLASS_INSTANCE(ompi_cxx_intercept_file_extra_state_item_t, opal_list_item_t,  | 
 | 28 | +                   NULL, NULL);  | 
 | 29 | + | 
 | 30 | +ompi_cxx_communicator_type_t ompi_cxx_comm_get_type (MPI_Comm comm)  | 
 | 31 | +{  | 
 | 32 | +    if (OMPI_COMM_IS_GRAPH(comm)) {  | 
 | 33 | +        return OMPI_CXX_COMM_TYPE_GRAPH;  | 
 | 34 | +    } else if (OMPI_COMM_IS_CART(comm)) {  | 
 | 35 | +        return OMPI_CXX_COMM_TYPE_CART;  | 
 | 36 | +    } else if (OMPI_COMM_IS_INTRA(comm)) {  | 
 | 37 | +        return OMPI_CXX_COMM_TYPE_INTRACOMM;  | 
 | 38 | +    } else if (OMPI_COMM_IS_INTER(comm)) {  | 
 | 39 | +        return OMPI_CXX_COMM_TYPE_INTERCOMM;  | 
 | 40 | +    }  | 
 | 41 | + | 
 | 42 | +    return OMPI_CXX_COMM_TYPE_UNKNOWN;  | 
 | 43 | +}  | 
 | 44 | + | 
 | 45 | +int ompi_cxx_errhandler_invoke_comm (MPI_Comm comm, int ret, const char *message)  | 
 | 46 | +{  | 
 | 47 | +    return OMPI_ERRHANDLER_INVOKE (comm, ret, message);  | 
 | 48 | +}  | 
 | 49 | + | 
 | 50 | +int ompi_cxx_errhandler_invoke_file (MPI_File file, int ret, const char *message)  | 
 | 51 | +{  | 
 | 52 | +    return OMPI_ERRHANDLER_INVOKE (file, ret, message);  | 
 | 53 | +}  | 
 | 54 | + | 
 | 55 | +int ompi_cxx_attr_create_keyval_comm (MPI_Comm_copy_attr_function *copy_fn,  | 
 | 56 | +                                      MPI_Comm_delete_attr_function* delete_fn, int *keyval, void *extra_state,  | 
 | 57 | +                                      int flags, void *bindings_extra_state)  | 
 | 58 | +{  | 
 | 59 | +    ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_communicator_copy_fn =  | 
 | 60 | +                                               (MPI_Comm_internal_copy_attr_function *) copy_fn};  | 
 | 61 | +    ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_communicator_delete_fn =  | 
 | 62 | +                                                 (MPI_Comm_delete_attr_function *) delete_fn};  | 
 | 63 | + | 
 | 64 | +    return ompi_attr_create_keyval (COMM_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, bindings_extra_state);  | 
 | 65 | +}  | 
 | 66 | + | 
 | 67 | +int ompi_cxx_attr_create_keyval_win (MPI_Win_copy_attr_function *copy_fn,  | 
 | 68 | +                                      MPI_Win_delete_attr_function* delete_fn, int *keyval, void *extra_state,  | 
 | 69 | +                                      int flags, void *bindings_extra_state)  | 
 | 70 | +{  | 
 | 71 | +    ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_win_copy_fn =  | 
 | 72 | +                                               (MPI_Win_internal_copy_attr_function *) copy_fn};  | 
 | 73 | +    ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_win_delete_fn =  | 
 | 74 | +                                                 (MPI_Win_delete_attr_function *) delete_fn};  | 
 | 75 | + | 
 | 76 | +    return ompi_attr_create_keyval (WIN_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, NULL);  | 
 | 77 | +}  | 
 | 78 | + | 
 | 79 | +int ompi_cxx_attr_create_keyval_type (MPI_Type_copy_attr_function *copy_fn,  | 
 | 80 | +                                      MPI_Type_delete_attr_function* delete_fn, int *keyval, void *extra_state,  | 
 | 81 | +                                      int flags, void *bindings_extra_state)  | 
 | 82 | +{  | 
 | 83 | +    ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_datatype_copy_fn =  | 
 | 84 | +                                               (MPI_Type_internal_copy_attr_function *) copy_fn};  | 
 | 85 | +    ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_datatype_delete_fn =  | 
 | 86 | +                                                 (MPI_Type_delete_attr_function *) delete_fn};  | 
 | 87 | + | 
 | 88 | +    return ompi_attr_create_keyval (TYPE_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, NULL);  | 
 | 89 | +}  | 
 | 90 | + | 
 | 91 | +MPI_Errhandler ompi_cxx_errhandler_create_comm (void *fn)  | 
 | 92 | +{  | 
 | 93 | +    ompi_errhandler_t *errhandler;  | 
 | 94 | +    errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_COMM,  | 
 | 95 | +                                        (ompi_errhandler_generic_handler_fn_t *) fn,  | 
 | 96 | +                                        OMPI_ERRHANDLER_LANG_CXX);  | 
 | 97 | +    errhandler->eh_cxx_dispatch_fn =  | 
 | 98 | +        (ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_comm_errhandler_invoke;  | 
 | 99 | +    return errhandler;  | 
 | 100 | +}  | 
 | 101 | + | 
 | 102 | +MPI_Errhandler ompi_cxx_errhandler_create_win (void *fn)  | 
 | 103 | +{  | 
 | 104 | +    ompi_errhandler_t *errhandler;  | 
 | 105 | +    errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_WIN,  | 
 | 106 | +                                        (ompi_errhandler_generic_handler_fn_t *) fn,  | 
 | 107 | +                                        OMPI_ERRHANDLER_LANG_CXX);  | 
 | 108 | +    errhandler->eh_cxx_dispatch_fn =  | 
 | 109 | +        (ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_win_errhandler_invoke;  | 
 | 110 | +    return errhandler;  | 
 | 111 | +}  | 
 | 112 | + | 
 | 113 | +MPI_Errhandler ompi_cxx_errhandler_create_file (void *fn)  | 
 | 114 | +{  | 
 | 115 | +    ompi_errhandler_t *errhandler;  | 
 | 116 | +    errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_FILE,  | 
 | 117 | +                                        (ompi_errhandler_generic_handler_fn_t *) fn,  | 
 | 118 | +                                        OMPI_ERRHANDLER_LANG_CXX);  | 
 | 119 | +    errhandler->eh_cxx_dispatch_fn =  | 
 | 120 | +        (ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_file_errhandler_invoke;  | 
 | 121 | +    return errhandler;  | 
 | 122 | +}  | 
 | 123 | + | 
 | 124 | +ompi_cxx_intercept_file_extra_state_t  | 
 | 125 | +*ompi_cxx_new_intercept_state (void *read_fn_cxx, void *write_fn_cxx, void *extent_fn_cxx,  | 
 | 126 | +                               void *extra_state_cxx)  | 
 | 127 | +{  | 
 | 128 | +    ompi_cxx_intercept_file_extra_state_item_t *intercept;  | 
 | 129 | + | 
 | 130 | +    intercept = OBJ_NEW(ompi_cxx_intercept_file_extra_state_item_t);  | 
 | 131 | +    if (NULL == intercept) {  | 
 | 132 | +        return NULL;  | 
 | 133 | +    }  | 
 | 134 | + | 
 | 135 | +    opal_list_append(&ompi_registered_datareps, &intercept->super);  | 
 | 136 | +    intercept->state.read_fn_cxx = read_fn_cxx;  | 
 | 137 | +    intercept->state.write_fn_cxx = write_fn_cxx;  | 
 | 138 | +    intercept->state.extent_fn_cxx = extent_fn_cxx;  | 
 | 139 | +    intercept->state.extra_state_cxx = extra_state_cxx;  | 
 | 140 | + | 
 | 141 | +    return &intercept->state;  | 
 | 142 | +}  | 
 | 143 | + | 
 | 144 | +void ompi_cxx_errhandler_set_dispatch_fn (ompi_errhandler_t *errhandler,  | 
 | 145 | +                                          ompi_errhandler_cxx_dispatch_fn_t *dispatch_fn)  | 
 | 146 | +{  | 
 | 147 | +    errhandler->eh_cxx_dispatch_fn = dispatch_fn;  | 
 | 148 | +}  | 
 | 149 | + | 
 | 150 | +void ompi_cxx_errhandler_set_callbacks (struct ompi_errhandler_t *errhandler, MPI_Comm_errhandler_function *eh_comm_fn,  | 
 | 151 | +                                        ompi_file_errhandler_fn *eh_file_fn, MPI_Win_errhandler_function *eh_win_fn)  | 
 | 152 | +{  | 
 | 153 | +    errhandler->eh_comm_fn = eh_comm_fn;  | 
 | 154 | +#if OMPI_PROVIDE_MPI_FILE_INTERFACE  | 
 | 155 | +    errhandler->eh_file_fn = eh_file_fn;  | 
 | 156 | +#endif  | 
 | 157 | +    errhandler->eh_win_fn = eh_win_fn;  | 
 | 158 | +}  | 
0 commit comments