File: osc_base_obj_convert.c

package info (click to toggle)
openmpi 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 60,812 kB
  • sloc: ansic: 307,904; sh: 39,104; cpp: 19,228; makefile: 8,573; asm: 3,627; lex: 901; perl: 362; yacc: 275; csh: 188; fortran: 175; f90: 126; tcl: 12
file content (257 lines) | stat: -rw-r--r-- 11,808 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University.
 *                         All rights reserved.
 * Copyright (c) 2004-2006 The Trustees of the University of Tennessee.
 *                         All rights reserved.
 * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart, 
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2007      Los Alamos National Security, LLC.  All rights
 *                         reserved. 
 * Copyright (c) 2009      Sun Microsystems, Inc. All rights reserved.
 * $COPYRIGHT$
 * 
 * Additional copyrights may follow
 * 
 * $HEADER$
 */

/*
 * utility functions for dealing with remote datatype and op structures
 */

#include "ompi_config.h"

#include "ompi/op/op.h"
#include "ompi/datatype/datatype.h"
#include "ompi/datatype/datatype_internal.h"
#include "ompi/datatype/convertor.h"
#include "ompi/datatype/convertor_internal.h"
#include "ompi/datatype/datatype_prototypes.h"

#include "osc_base_obj_convert.h"
#include "ompi/memchecker.h"

int
ompi_osc_base_get_primitive_type_info(ompi_datatype_t *datatype,
                                      ompi_datatype_t **prim_datatype, 
                                      uint32_t *prim_count)
{
    struct ompi_datatype_t *primitive_datatype = NULL;
    uint32_t primitive_count;

    /* get underlying type... */
    if (ompi_ddt_is_predefined(datatype)) {
        primitive_datatype = datatype;
        primitive_count = 1;
    } else {
        int i, found_index = -1;
        uint64_t mask = 1;
        for (i = 0 ; i < DT_MAX_PREDEFINED ; ++i) {
            if (datatype->bdt_used & mask) {
                found_index = i;
                break;
            }
            mask *= 2;
        }
        primitive_datatype = (ompi_datatype_t*)
            ompi_ddt_basicDatatypes[found_index];
        primitive_count = datatype->nbElems;
    }

    *prim_datatype = primitive_datatype;
    *prim_count = primitive_count;

    return OMPI_SUCCESS;
}


struct ompi_osc_base_convertor_t {
    ompi_convertor_t convertor;
    ompi_op_t *op;
    ompi_datatype_t *datatype;
};
typedef struct ompi_osc_base_convertor_t ompi_osc_base_convertor_t;
static OBJ_CLASS_INSTANCE(ompi_osc_base_convertor_t, ompi_convertor_t, NULL, NULL);

#define COPY_TYPE( TYPENAME, TYPE, COUNT )                              \
static int copy_##TYPENAME( ompi_convertor_t *pConvertor, uint32_t count, \
                            char* from, size_t from_len, ptrdiff_t from_extent, \
                            char* to, size_t to_len, ptrdiff_t to_extent, \
                            ptrdiff_t *advance)                         \
{                                                                       \
    size_t remote_TYPE_size = sizeof(TYPE) * (COUNT); /* TODO */        \
    size_t local_TYPE_size = (COUNT) * sizeof(TYPE);                    \
    ompi_osc_base_convertor_t *osc_convertor =                          \
        (ompi_osc_base_convertor_t*) pConvertor;                        \
                                                                        \
    if( (from_extent == (ptrdiff_t)local_TYPE_size) &&                  \
        (to_extent == (ptrdiff_t)remote_TYPE_size) ) {                  \
        ompi_op_reduce(osc_convertor->op, from, to, count, osc_convertor->datatype); \
    } else {                                                            \
        uint32_t i;                                                     \
        for( i = 0; i < count; i++ ) {                                  \
            ompi_op_reduce(osc_convertor->op, from, to, 1, osc_convertor->datatype); \
            to += to_extent;                                            \
            from += from_extent;                                        \
        }                                                               \
    }                                                                   \
    *advance = count * from_extent;                                     \
    return count;                                                       \
}

/* set up copy functions for the basic C MPI data types */
COPY_TYPE( char, char, 1 )
COPY_TYPE( short, short, 1 )
COPY_TYPE( int, int, 1 )
COPY_TYPE( long, long, 1 )
COPY_TYPE( long_long, long long, 1 )
COPY_TYPE( float, float, 1 )
COPY_TYPE( double, double, 1 )
COPY_TYPE( long_double, long double, 1 )
COPY_TYPE( complex_float, ompi_complex_float_t, 1 )
COPY_TYPE( complex_double, ompi_complex_double_t, 1 )
COPY_TYPE( complex_long_double, ompi_complex_long_double_t, 1 )

/* table of predefined copy functions - one for each MPI type */
static conversion_fct_t ompi_osc_base_copy_functions[DT_MAX_PREDEFINED] = {
   (conversion_fct_t)NULL,                      /* DT_LOOP                */
   (conversion_fct_t)NULL,                      /* DT_END_LOOP            */
   (conversion_fct_t)NULL,                      /* DT_LB                  */
   (conversion_fct_t)NULL,                      /* DT_UB                  */
   (conversion_fct_t)copy_char,                 /* DT_CHAR                */
   (conversion_fct_t)copy_char,                 /* DT_CHARACTER           */
   (conversion_fct_t)copy_char,                 /* DT_UNSIGNED_CHAR       */
   (conversion_fct_t)copy_char,                 /* DT_SIGNED_CHAR       */
   (conversion_fct_t)copy_char,                 /* DT_BYTE                */
   (conversion_fct_t)copy_short,                /* DT_SHORT               */
   (conversion_fct_t)copy_short,                /* DT_UNSIGNED_SHORT      */
   (conversion_fct_t)copy_int,                  /* DT_INT                 */
   (conversion_fct_t)copy_int,                  /* DT_UNSIGNED_INT        */
   (conversion_fct_t)copy_long,                 /* DT_LONG                */
   (conversion_fct_t)copy_long,                 /* DT_UNSIGNED_LONG       */
   (conversion_fct_t)copy_long_long,            /* DT_LONG_LONG_INT       */
   (conversion_fct_t)copy_long_long,            /* DT_UNSIGNED_LONG_LONG  */
   (conversion_fct_t)copy_float,                /* DT_FLOAT               */
   (conversion_fct_t)copy_double,               /* DT_DOUBLE              */
   (conversion_fct_t)copy_long_double,          /* DT_LONG_DOUBLE         */
   (conversion_fct_t)NULL,                      /* DT_PACKED              */
   (conversion_fct_t)NULL,                      /* DT_WCHAR               */
#if SIZEOF_BOOL == SIZEOF_CHAR
   (conversion_fct_t)copy_char,                 /* DT_CXX_BOOL            */
#elif SIZEOF_BOOL == SIZEOF_SHORT
   (conversion_fct_t)copy_short,                /* DT_CXX_BOOL            */
#elif SIZEOF_BOOL == SIZEOF_INT
   (conversion_fct_t)copy_int,                  /* DT_CXX_BOOL            */
#elif SIZEOF_BOOL == SIZEOF_LONG
   (conversion_fct_t)copy_long,                 /* DT_CXX_BOOL            */
#else
   (conversion_fct_t)NULL,                      /* DT_CXX_BOOL            */
#endif
#if OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_CHAR
   (conversion_fct_t)copy_char,                 /* DT_LOGIC               */
#elif OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_SHORT
   (conversion_fct_t)copy_short,                /* DT_LOGIC               */
#elif OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_INT
   (conversion_fct_t)copy_int,                  /* DT_LOGIC               */
#elif OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_LONG
   (conversion_fct_t)copy_long,                 /* DT_LOGIC               */
#else
   (conversion_fct_t)NULL,                      /* DT_LOGIC               */
#endif
   (conversion_fct_t)copy_int,                  /* DT_INTEGER             */
   (conversion_fct_t)copy_float,                /* DT_REAL                */
   (conversion_fct_t)copy_double,               /* DT_DBLPREC             */
   (conversion_fct_t)copy_complex_float,        /* DT_COMPLEX_FLOAT       */
   (conversion_fct_t)copy_complex_double,       /* DT_COMPLEX_DOUBLE      */
   (conversion_fct_t)copy_complex_long_double,  /* DT_COMPLEX_LONG_DOUBLE */
   (conversion_fct_t)NULL,                      /* DT_2INT                */
   (conversion_fct_t)NULL,                      /* DT_2INTEGER            */
   (conversion_fct_t)NULL,                      /* DT_2REAL               */
   (conversion_fct_t)NULL,                      /* DT_2DBLPREC            */
   (conversion_fct_t)NULL,                      /* DT_2COMPLEX            */
   (conversion_fct_t)NULL,                      /* DT_2DOUBLE_COMPLEX     */
   (conversion_fct_t)NULL,                      /* DT_FLOAT_INT           */
   (conversion_fct_t)NULL,                      /* DT_DOUBLE_INT          */
   (conversion_fct_t)NULL,                      /* DT_LONG_DOUBLE_INT     */
   (conversion_fct_t)NULL,                      /* DT_LONG_INT            */
   (conversion_fct_t)NULL,                      /* DT_SHORT_INT           */
   (conversion_fct_t)NULL,                      /* DT_UNAVAILABLE         */
};

int
ompi_osc_base_process_op(void *outbuf,
                         void *inbuf,
                         size_t inbuflen,
                         struct ompi_datatype_t *datatype,
                         int count,
                         ompi_op_t *op)
{
    if (op == &ompi_mpi_op_replace.op) {
        return OMPI_ERR_NOT_SUPPORTED;
    }

    if (ompi_ddt_is_predefined(datatype)) {
        ompi_op_reduce(op, inbuf, outbuf, count, datatype);
    } else {
        struct ompi_datatype_t *primitive_datatype = NULL;
        uint32_t primitive_count;
        ompi_osc_base_convertor_t convertor;
        struct iovec iov;
        uint32_t iov_count = 1;
        size_t max_data;
        struct ompi_convertor_master_t master = {NULL, 0, 0, 0, {0, }, NULL};
        int i, found_index = -1;
        uint64_t mask = 1;

        for (i = 0 ; i < DT_MAX_PREDEFINED ; ++i) {
            if (datatype->bdt_used & mask) {
                found_index = i;
                break;
            }
            mask *= 2;
        }
        primitive_datatype = (ompi_datatype_t*)
            ompi_ddt_basicDatatypes[found_index];
        primitive_count = datatype->nbElems;

        /* create convertor */
        OBJ_CONSTRUCT(&convertor, ompi_osc_base_convertor_t);
        convertor.op = op;
        convertor.datatype = primitive_datatype;

        /* initialize convertor */
        ompi_convertor_copy_and_prepare_for_recv(ompi_proc_local()->proc_convertor,
                                                 datatype,
                                                 count,
                                                 outbuf,
                                                 0,
                                                 &convertor.convertor);

        memcpy(&master, convertor.convertor.master, sizeof(struct ompi_convertor_master_t));
        master.next = convertor.convertor.master;
        master.pFunctions = (conversion_fct_t*) &ompi_osc_base_copy_functions;
        convertor.convertor.master = &master;
        convertor.convertor.fAdvance = ompi_unpack_general;

        iov.iov_len  = inbuflen;
        iov.iov_base = (IOVBASE_TYPE*) inbuf;
        max_data     = iov.iov_len;
        MEMCHECKER(
            memchecker_convertor_call(&opal_memchecker_base_mem_defined,
                                      &convertor.convertor);
        );
        ompi_convertor_unpack(&convertor.convertor, 
                              &iov,
                              &iov_count,
                              &max_data);
        MEMCHECKER(
            memchecker_convertor_call(&opal_memchecker_base_mem_noaccess,
                                      &convertor.convertor);
        );
        OBJ_DESTRUCT(&convertor);
    }

    return OMPI_SUCCESS;
}