File: file.cc

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (227 lines) | stat: -rw-r--r-- 7,949 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// -*- c++ -*-
// 
// Copyright (c) 2006      Los Alamos National Security, LLC.  All rights
//                         reserved. 
// Copyright (c) 2007-2009 Cisco Systems, Inc.  All rights reserved.
// $COPYRIGHT$
// 
// Additional copyrights may follow
// 
// $HEADER$
//

// Do not include ompi_config.h before mpi.h because it causes
// malloc/free problems due to setting OMPI_BUILDING to 1
#include "mpi.h"

#include "ompi/constants.h"
#include "ompi/mpi/cxx/mpicxx.h"
#include "opal/class/opal_list.h"
#include "ompi/file/file.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/runtime/mpiruntime.h"

void 
MPI::File::Close() 
{
    (void) MPI_File_close(&mpi_file);
}

  
MPI::Errhandler 
MPI::File::Create_errhandler(MPI::File::Errhandler_function* function)
{
    MPI_Errhandler c_errhandler = 
        ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_FILE,
                               (ompi_errhandler_generic_handler_fn_t*) function,
                               OMPI_ERRHANDLER_LANG_CXX);
    c_errhandler->eh_cxx_dispatch_fn = 
        (ompi_errhandler_cxx_dispatch_fn_t*)
        ompi_mpi_cxx_file_errhandler_invoke;
    return c_errhandler;
}


//
// Infrastructure for MPI_REGISTER_DATAREP
//
// Similar to what we have to do in the F77 bindings: call the C
// MPI_Register_datarep function with "intercept" callback functions
// that conform to the C bindings.  In these intercepts, convert the
// arguments to C++ calling convertions, and then invoke the actual
// C++ callbacks.

// Data structure passed to the intercepts (see below).  It is an OPAL
// list_item_t so that we can clean this memory up during
// MPI_FINALIZE.
typedef struct intercept_extra_state {
    opal_list_item_t base;
    MPI::Datarep_conversion_function *read_fn_cxx;
    MPI::Datarep_conversion_function *write_fn_cxx;
    MPI::Datarep_extent_function *extent_fn_cxx;
    void *extra_state_cxx;
} intercept_extra_state_t;

static void intercept_extra_state_constructor(intercept_extra_state_t *obj)
{
    obj->read_fn_cxx = NULL;
    obj->write_fn_cxx = NULL;
    obj->extent_fn_cxx = NULL;
    obj->extra_state_cxx = NULL;
}

OBJ_CLASS_DECLARATION(intercept_extra_state_t);
OBJ_CLASS_INSTANCE(intercept_extra_state_t,
                   opal_list_item_t,
                   intercept_extra_state_constructor, NULL);

// Intercept function for read conversions
static int read_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
                             void *filebuf, MPI_Offset position_c, 
                             void *extra_state)
{
    MPI::Datatype type_cxx(type_c);
    MPI::Offset position_cxx(position_c);
    intercept_extra_state_t *intercept_data = 
        (intercept_extra_state_t*) extra_state;

    intercept_data->read_fn_cxx(userbuf, type_cxx, count_c, filebuf,
                                position_cxx, intercept_data->extra_state_cxx);
    return MPI_SUCCESS;
}

// Intercept function for write conversions
static int write_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
                             void *filebuf, MPI_Offset position_c, 
                              void *extra_state)
{
    MPI::Datatype type_cxx(type_c);
    MPI::Offset position_cxx(position_c);
    intercept_extra_state_t *intercept_data = 
        (intercept_extra_state_t*) extra_state;

    intercept_data->write_fn_cxx(userbuf, type_cxx, count_c, filebuf,
                                 position_cxx, intercept_data->extra_state_cxx);
    return MPI_SUCCESS;
}

// Intercept function for extent calculations
static int extent_intercept_fn(MPI_Datatype type_c, MPI_Aint *file_extent_c, 
                               void *extra_state)
{
    MPI::Datatype type_cxx(type_c);
    MPI::Aint file_extent_cxx(*file_extent_c);
    intercept_extra_state_t *intercept_data = 
        (intercept_extra_state_t*) extra_state;

    intercept_data->extent_fn_cxx(type_cxx, file_extent_cxx, 
                                  intercept_data->extra_state_cxx);
    *file_extent_c = file_extent_cxx;
    return MPI_SUCCESS;
}

// C++ bindings for MPI::Register_datarep
void 
MPI::Register_datarep(const char* datarep, 
                      Datarep_conversion_function* read_fn_cxx, 
                      Datarep_conversion_function* write_fn_cxx, 
                      Datarep_extent_function* extent_fn_cxx, 
                      void* extra_state_cxx)
{
    intercept_extra_state_t *intercept;

    intercept = OBJ_NEW(intercept_extra_state_t);
    if (NULL == intercept) {
        OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE, 
                               "MPI::Register_datarep");
        return;
    }
    opal_list_append(&ompi_registered_datareps, &(intercept->base));
    intercept->read_fn_cxx = read_fn_cxx;
    intercept->write_fn_cxx = write_fn_cxx;
    intercept->extent_fn_cxx = extent_fn_cxx;
    intercept->extra_state_cxx = extra_state_cxx;

    (void)MPI_Register_datarep(const_cast<char*>(datarep), read_intercept_fn, 
                               write_intercept_fn,
                               extent_intercept_fn, intercept);
}


void 
MPI::Register_datarep(const char* datarep, 
                      MPI_Datarep_conversion_function* read_fn_c,
                      Datarep_conversion_function* write_fn_cxx, 
                      Datarep_extent_function* extent_fn_cxx, 
                      void* extra_state_cxx)
{
    intercept_extra_state_t *intercept;

    intercept = OBJ_NEW(intercept_extra_state_t);
    if (NULL == intercept) {
        OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE, 
                               "MPI::Register_datarep");
        return;
    }
    opal_list_append(&ompi_registered_datareps, &(intercept->base));
    intercept->write_fn_cxx = write_fn_cxx;
    intercept->extent_fn_cxx = extent_fn_cxx;
    intercept->extra_state_cxx = extra_state_cxx;

    (void)MPI_Register_datarep(const_cast<char*>(datarep), read_fn_c, 
                               write_intercept_fn,
                               extent_intercept_fn, intercept);
}


void 
MPI::Register_datarep(const char* datarep, 
                      Datarep_conversion_function* read_fn_cxx, 
                      MPI_Datarep_conversion_function* write_fn_c, 
                      Datarep_extent_function* extent_fn_cxx, 
                      void* extra_state_cxx)
{
    intercept_extra_state_t *intercept;

    intercept = OBJ_NEW(intercept_extra_state_t);
    if (NULL == intercept) {
        OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE, 
                               "MPI::Register_datarep");
        return;
    }
    opal_list_append(&ompi_registered_datareps, &(intercept->base));
    intercept->read_fn_cxx = read_fn_cxx;
    intercept->extent_fn_cxx = extent_fn_cxx;
    intercept->extra_state_cxx = extra_state_cxx;

    (void)MPI_Register_datarep(const_cast<char*>(datarep), read_intercept_fn,
                               write_fn_c,
                               extent_intercept_fn, intercept);
}


void 
MPI::Register_datarep(const char* datarep, 
                      MPI_Datarep_conversion_function* read_fn_c,
                      MPI_Datarep_conversion_function* write_fn_c, 
                      Datarep_extent_function* extent_fn_cxx, 
                      void* extra_state_cxx)
{
    intercept_extra_state_t *intercept;

    intercept = OBJ_NEW(intercept_extra_state_t);
    if (NULL == intercept) {
        OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, OMPI_ERR_OUT_OF_RESOURCE, 
                               "MPI::Register_datarep");
        return;
    }
    opal_list_append(&ompi_registered_datareps, &(intercept->base));
    intercept->extent_fn_cxx = extent_fn_cxx;
    intercept->extra_state_cxx = extra_state_cxx;

    (void)MPI_Register_datarep(const_cast<char*>(datarep), read_fn_c, 
                               write_fn_c,
                               extent_intercept_fn, intercept);
}