root/ompi/mpi/cxx/file.cc

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

DEFINITIONS

This source file includes following definitions.
  1. Close
  2. Create_errhandler
  3. read_intercept_fn
  4. write_intercept_fn
  5. extent_intercept_fn
  6. Register_datarep
  7. Register_datarep
  8. Register_datarep
  9. Register_datarep

   1 // -*- c++ -*-
   2 //
   3 // Copyright (c) 2006-2016 Los Alamos National Security, LLC.  All rights
   4 //                         reserved.
   5 // Copyright (c) 2007-2009 Cisco Systems, Inc.  All rights reserved.
   6 // $COPYRIGHT$
   7 //
   8 // Additional copyrights may follow
   9 //
  10 // $HEADER$
  11 //
  12 
  13 // Do not include ompi_config.h before mpi.h because it causes
  14 // malloc/free problems due to setting OMPI_BUILDING to 1
  15 #include "mpi.h"
  16 
  17 #include "ompi/constants.h"
  18 #include "ompi/mpi/cxx/mpicxx.h"
  19 #include "cxx_glue.h"
  20 
  21 void
  22 MPI::File::Close()
  23 {
  24     (void) MPI_File_close(&mpi_file);
  25 }
  26 
  27 
  28 MPI::Errhandler
  29 MPI::File::Create_errhandler(MPI::File::Errhandler_function* function)
  30 {
  31     return ompi_cxx_errhandler_create_file ((ompi_cxx_dummy_fn_t *) function);
  32 }
  33 
  34 
  35 //
  36 // Infrastructure for MPI_REGISTER_DATAREP
  37 //
  38 // Similar to what we have to do in the F77 bindings: call the C
  39 // MPI_Register_datarep function with "intercept" callback functions
  40 // that conform to the C bindings.  In these intercepts, convert the
  41 // arguments to C++ calling convertions, and then invoke the actual
  42 // C++ callbacks.
  43 
  44 // Data structure passed to the intercepts (see below).  It is an OPAL
  45 // list_item_t so that we can clean this memory up during
  46 // MPI_FINALIZE.
  47 
  48 // Intercept function for read conversions
  49 static int read_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
  50                              void *filebuf, MPI_Offset position_c,
  51                              void *extra_state)
  52 {
  53     MPI::Datatype type_cxx(type_c);
  54     MPI::Offset position_cxx(position_c);
  55     ompi_cxx_intercept_file_extra_state_t *intercept_data =
  56         (ompi_cxx_intercept_file_extra_state_t*) extra_state;
  57     MPI::Datarep_conversion_function *read_fn_cxx =
  58         (MPI::Datarep_conversion_function *) intercept_data->read_fn_cxx;
  59 
  60     read_fn_cxx (userbuf, type_cxx, count_c, filebuf, position_cxx,
  61                  intercept_data->extra_state_cxx);
  62     return MPI_SUCCESS;
  63 }
  64 
  65 // Intercept function for write conversions
  66 static int write_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
  67                              void *filebuf, MPI_Offset position_c,
  68                               void *extra_state)
  69 {
  70     MPI::Datatype type_cxx(type_c);
  71     MPI::Offset position_cxx(position_c);
  72     ompi_cxx_intercept_file_extra_state_t *intercept_data =
  73         (ompi_cxx_intercept_file_extra_state_t*) extra_state;
  74     MPI::Datarep_conversion_function *write_fn_cxx =
  75         (MPI::Datarep_conversion_function *) intercept_data->write_fn_cxx;
  76 
  77     write_fn_cxx (userbuf, type_cxx, count_c, filebuf, position_cxx,
  78                   intercept_data->extra_state_cxx);
  79     return MPI_SUCCESS;
  80 }
  81 
  82 // Intercept function for extent calculations
  83 static int extent_intercept_fn(MPI_Datatype type_c, MPI_Aint *file_extent_c,
  84                                void *extra_state)
  85 {
  86     MPI::Datatype type_cxx(type_c);
  87     MPI::Aint file_extent_cxx(*file_extent_c);
  88     ompi_cxx_intercept_file_extra_state_t *intercept_data =
  89         (ompi_cxx_intercept_file_extra_state_t*) extra_state;
  90     MPI::Datarep_extent_function *extent_fn_cxx =
  91         (MPI::Datarep_extent_function *) intercept_data->extent_fn_cxx;
  92 
  93     extent_fn_cxx (type_cxx, file_extent_cxx, intercept_data->extra_state_cxx);
  94     *file_extent_c = file_extent_cxx;
  95     return MPI_SUCCESS;
  96 }
  97 
  98 // C++ bindings for MPI::Register_datarep
  99 void
 100 MPI::Register_datarep(const char* datarep,
 101                       Datarep_conversion_function* read_fn_cxx,
 102                       Datarep_conversion_function* write_fn_cxx,
 103                       Datarep_extent_function* extent_fn_cxx,
 104                       void* extra_state_cxx)
 105 {
 106     ompi_cxx_intercept_file_extra_state_t *intercept;
 107 
 108     intercept = ompi_cxx_new_intercept_state ((void *) read_fn_cxx, (void *) write_fn_cxx,
 109                                               (void *) extent_fn_cxx, extra_state_cxx);
 110     if (NULL == intercept) {
 111         ompi_cxx_errhandler_invoke_file (MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE,
 112                                          "MPI::Register_datarep");
 113         return;
 114     }
 115 
 116     (void)MPI_Register_datarep (const_cast<char*>(datarep), read_intercept_fn,
 117                                 write_intercept_fn, extent_intercept_fn, intercept);
 118 }
 119 
 120 
 121 void
 122 MPI::Register_datarep(const char* datarep,
 123                       MPI_Datarep_conversion_function* read_fn_c,
 124                       Datarep_conversion_function* write_fn_cxx,
 125                       Datarep_extent_function* extent_fn_cxx,
 126                       void* extra_state_cxx)
 127 {
 128     ompi_cxx_intercept_file_extra_state_t *intercept;
 129 
 130     intercept = ompi_cxx_new_intercept_state (NULL, (void *) write_fn_cxx, (void *) extent_fn_cxx,
 131                                               extra_state_cxx);
 132     if (NULL == intercept) {
 133         ompi_cxx_errhandler_invoke_file (MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE,
 134                                          "MPI::Register_datarep");
 135         return;
 136     }
 137 
 138     (void)MPI_Register_datarep (const_cast<char*>(datarep), read_fn_c, write_intercept_fn,
 139                                 extent_intercept_fn, intercept);
 140 }
 141 
 142 
 143 void
 144 MPI::Register_datarep(const char* datarep,
 145                       Datarep_conversion_function* read_fn_cxx,
 146                       MPI_Datarep_conversion_function* write_fn_c,
 147                       Datarep_extent_function* extent_fn_cxx,
 148                       void* extra_state_cxx)
 149 {
 150     ompi_cxx_intercept_file_extra_state_t *intercept;
 151 
 152     intercept = ompi_cxx_new_intercept_state ((void *) read_fn_cxx, NULL, (void *) extent_fn_cxx,
 153                                               extra_state_cxx);
 154     if (NULL == intercept) {
 155         ompi_cxx_errhandler_invoke_file (MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE,
 156                                          "MPI::Register_datarep");
 157         return;
 158     }
 159 
 160     (void)MPI_Register_datarep (const_cast<char*>(datarep), read_intercept_fn, write_fn_c,
 161                                 extent_intercept_fn, intercept);
 162 }
 163 
 164 
 165 void
 166 MPI::Register_datarep(const char* datarep,
 167                       MPI_Datarep_conversion_function* read_fn_c,
 168                       MPI_Datarep_conversion_function* write_fn_c,
 169                       Datarep_extent_function* extent_fn_cxx,
 170                       void* extra_state_cxx)
 171 {
 172     ompi_cxx_intercept_file_extra_state_t *intercept;
 173 
 174     intercept = ompi_cxx_new_intercept_state (NULL, NULL, (void *) extent_fn_cxx, extra_state_cxx);
 175     if (NULL == intercept) {
 176         ompi_cxx_errhandler_invoke_file (MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE,
 177                                          "MPI::Register_datarep");
 178         return;
 179     }
 180 
 181     (void)MPI_Register_datarep (const_cast<char*>(datarep), read_fn_c, write_fn_c,
 182                                 extent_intercept_fn, intercept);
 183 }
 184 
 185 

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