File: datatype_inln.h

package info (click to toggle)
openmpi 4.1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 127,592 kB
  • sloc: ansic: 690,998; makefile: 43,047; f90: 19,220; sh: 7,182; java: 6,360; perl: 3,590; cpp: 2,227; python: 1,350; lex: 989; fortran: 61; tcl: 12
file content (418 lines) | stat: -rw-r--r-- 12,463 bytes parent folder | download | duplicates (4)
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
// -*- c++ -*-
//
// Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
//                         University Research and Technology
//                         Corporation.  All rights reserved.
// Copyright (c) 2004-2005 The University of Tennessee and The University
//                         of Tennessee Research Foundation.  All rights
//                         reserved.
// Copyright (c) 2004-2005 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) 2006-2008 Sun Microsystems, Inc.  All rights reserved.
// Copyright (c) 2011      FUJITSU LIMITED.  All rights reserved.

// $COPYRIGHT$
//
// Additional copyrights may follow
//
// $HEADER$
//


//
// Point-to-Point Communication
//

inline MPI::Datatype
MPI::Datatype::Create_contiguous(int count) const
{
  MPI_Datatype newtype;
  (void)MPI_Type_contiguous(count, mpi_datatype, &newtype);
  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_vector(int count, int blocklength,
			     int stride) const
{
  MPI_Datatype newtype;
  (void)MPI_Type_vector(count, blocklength, stride, mpi_datatype, &newtype);
  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_indexed(int count,
				     const int array_of_blocklengths[],
				     const int array_of_displacements[]) const
{
  MPI_Datatype newtype;
  (void)MPI_Type_indexed(count, const_cast<int *>(array_of_blocklengths),
			 const_cast<int *>(array_of_displacements), mpi_datatype, &newtype);
  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_struct(int count, const int array_of_blocklengths[],
				    const MPI::Aint array_of_displacements[],
				    const MPI::Datatype array_of_types[])
{
  MPI_Datatype newtype;
  int i;
  MPI_Datatype* type_array = new MPI_Datatype[count];
  for (i=0; i < count; i++)
    type_array[i] = array_of_types[i];

  (void)MPI_Type_create_struct(count, const_cast<int *>(array_of_blocklengths),
                               const_cast<MPI_Aint*>(array_of_displacements),
                               type_array, &newtype);
  delete[] type_array;
  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_hindexed(int count, const int array_of_blocklengths[],
				      const MPI::Aint array_of_displacements[]) const
{
  MPI_Datatype newtype;
  (void)MPI_Type_create_hindexed(count, const_cast<int *>(array_of_blocklengths),
                                 const_cast<MPI_Aint*>(array_of_displacements),
                                 mpi_datatype, &newtype) ;
  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_hvector(int count, int blocklength,
				     MPI::Aint stride) const
{
  MPI_Datatype newtype;
  (void)MPI_Type_create_hvector(count, blocklength, (MPI_Aint)stride,
                                mpi_datatype, &newtype);

  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_indexed_block(int count, int blocklength,
				    const int array_of_displacements[]) const
{
  MPI_Datatype newtype;
  (void)MPI_Type_create_indexed_block(count, blocklength, const_cast<int *>(array_of_displacements),
                                      mpi_datatype, &newtype);
  return newtype;
}

inline MPI::Datatype
MPI::Datatype::Create_resized(const MPI::Aint lb, const MPI::Aint extent) const
{
    MPI_Datatype newtype;

    (void) MPI_Type_create_resized(mpi_datatype, lb, extent, &newtype);
    return(newtype);
}

inline int
MPI::Datatype::Get_size() const
{
  int size;
  (void)MPI_Type_size(mpi_datatype, &size);
  return size;
}

inline void
MPI::Datatype::Get_extent(MPI::Aint& lb, MPI::Aint& extent) const
{
  (void)MPI_Type_get_extent(mpi_datatype, &lb, &extent);
}

inline void
MPI::Datatype::Get_true_extent(MPI::Aint& lb, MPI::Aint& extent) const
{
    (void) MPI_Type_get_true_extent(mpi_datatype, &lb, &extent);
}

inline void
MPI::Datatype::Commit()
{
  (void)MPI_Type_commit(&mpi_datatype);
}

inline void
MPI::Datatype::Pack(const void* inbuf, int incount,
			   void *outbuf, int outsize,
			   int& position, const MPI::Comm &comm) const
{
  (void)MPI_Pack(const_cast<void *>(inbuf), incount,  mpi_datatype, outbuf,
		 outsize, &position, comm);
}

inline void
MPI::Datatype::Unpack(const void* inbuf, int insize,
			     void *outbuf, int outcount, int& position,
			     const MPI::Comm& comm) const
{
  (void)MPI_Unpack(const_cast<void *>(inbuf), insize, &position,
		   outbuf, outcount, mpi_datatype, comm);
}

inline int
MPI::Datatype::Pack_size(int incount, const MPI::Comm& comm) const
{
  int size;
  (void)MPI_Pack_size(incount, mpi_datatype, comm, &size);
  return size;
}

inline void
MPI::Datatype::Pack_external(const char* datarep, const void* inbuf, int incount,
            void* outbuf, MPI::Aint outsize, MPI::Aint& position) const
{
    (void)MPI_Pack_external(const_cast<char *>(datarep), const_cast<void *>(inbuf),
                             incount, mpi_datatype, outbuf, outsize, &position);
}

inline MPI::Aint
MPI::Datatype::Pack_external_size(const char* datarep, int incount) const
{
    MPI_Aint addr;
    (void)MPI_Pack_external_size(const_cast<char *>(datarep), incount, mpi_datatype, &addr);
    return addr;
}

inline void
MPI::Datatype::Unpack_external(const char* datarep, const void* inbuf,
            MPI::Aint insize, MPI::Aint& position, void* outbuf, int outcount) const
{
    (void)MPI_Unpack_external(const_cast<char *>(datarep), const_cast<void *>(inbuf),
                               insize, &position, outbuf, outcount, mpi_datatype);
}

//
// Miscellany
//

inline MPI::Datatype
MPI::Datatype::Create_subarray(int ndims, const int array_of_sizes[],
				      const int array_of_subsizes[],
				      const int array_of_starts[], int order)
  const
{
  MPI_Datatype type;
  (void) MPI_Type_create_subarray(ndims, const_cast<int *>(array_of_sizes),
                                  const_cast<int *>(array_of_subsizes),
                                  const_cast<int *>(array_of_starts),
                                  order, mpi_datatype, &type);
  return type;
}

inline MPI::Datatype
MPI::Datatype::Create_darray(int size, int rank, int ndims,
                   const int array_of_gsizes[], const int array_of_distribs[],
                   const int array_of_dargs[],  const int array_of_psizes[],
                   int order) const
{
    MPI_Datatype type;
    (void) MPI_Type_create_darray(size, rank, ndims,
                   const_cast<int *>(array_of_gsizes),
                   const_cast<int *>(array_of_distribs),
                   const_cast<int *>(array_of_dargs),
                   const_cast<int *>(array_of_psizes),
                   order, mpi_datatype, &type);
    return type;
}

inline MPI::Datatype
MPI::Datatype::Create_f90_complex(int p, int r)
{
    MPI_Datatype type;
    (void) MPI_Type_create_f90_complex(p, r, &type);
    return type;
}

inline MPI::Datatype
MPI::Datatype::Create_f90_integer(int r)
{
    MPI_Datatype type;
    (void) MPI_Type_create_f90_integer(r, &type);
    return type;
}

inline MPI::Datatype
MPI::Datatype::Create_f90_real(int p, int r)
{
    MPI_Datatype type;
    (void) MPI_Type_create_f90_real(p, r, &type);
    return type;
}

inline MPI::Datatype
MPI::Datatype::Match_size(int typeclass, int size)
{
    MPI_Datatype type;
    (void) MPI_Type_match_size(typeclass, size, &type);
    return type;
}

//
// External Interfaces
//


inline MPI::Datatype
MPI::Datatype::Dup() const
{
  MPI_Datatype type;
  (void) MPI_Type_dup(mpi_datatype, &type);
  return type;
}


// 1) original Create_keyval that takes the first 2 arguments as C++
//    functions
inline int
MPI::Datatype::Create_keyval(MPI::Datatype::Copy_attr_function* type_copy_attr_fn,
                             MPI::Datatype::Delete_attr_function* type_delete_attr_fn,
                             void* extra_state)
{
    // Back-end function does the heavy lifting
    int ret, keyval;
    ret = do_create_keyval(NULL, NULL,
                           type_copy_attr_fn, type_delete_attr_fn,
                           extra_state, keyval);
    return (MPI_SUCCESS == ret) ? keyval : ret;
}

// 2) overload Create_keyval to take the first 2 arguments as C
//    functions
inline int
MPI::Datatype::Create_keyval(MPI_Type_copy_attr_function* type_copy_attr_fn,
                             MPI_Type_delete_attr_function* type_delete_attr_fn,
                             void* extra_state)
{
    // Back-end function does the heavy lifting
    int ret, keyval;
    ret = do_create_keyval(type_copy_attr_fn, type_delete_attr_fn,
                           NULL, NULL,
                           extra_state, keyval);
    return (MPI_SUCCESS == ret) ? keyval : ret;
}

// 3) overload Create_keyval to take the first 2 arguments as C++ & C
//    functions
inline int
MPI::Datatype::Create_keyval(MPI::Datatype::Copy_attr_function* type_copy_attr_fn,
                             MPI_Type_delete_attr_function* type_delete_attr_fn,
                             void* extra_state)
{
    // Back-end function does the heavy lifting
    int ret, keyval;
    ret = do_create_keyval(NULL, type_delete_attr_fn,
                           type_copy_attr_fn, NULL,
                           extra_state, keyval);
    return (MPI_SUCCESS == ret) ? keyval : ret;
}

// 4) overload Create_keyval to take the first 2 arguments as C & C++
//    functions
inline int
MPI::Datatype::Create_keyval(MPI_Type_copy_attr_function* type_copy_attr_fn,
                             MPI::Datatype::Delete_attr_function* type_delete_attr_fn,
                             void* extra_state)
{
    // Back-end function does the heavy lifting
    int ret, keyval;
    ret = do_create_keyval(type_copy_attr_fn, NULL,
                           NULL, type_delete_attr_fn,
                           extra_state, keyval);
    return (MPI_SUCCESS == ret) ? keyval : ret;
}

inline void
MPI::Datatype::Delete_attr(int type_keyval)
{
  (void) MPI_Type_delete_attr(mpi_datatype, type_keyval);
}

inline void
MPI::Datatype::Free_keyval(int& type_keyval)
{
    (void) MPI_Type_free_keyval(&type_keyval);
}

inline bool
MPI::Datatype::Get_attr(int type_keyval,
                          void* attribute_val) const
{
  int ret;
  (void) MPI_Type_get_attr(mpi_datatype, type_keyval, attribute_val, &ret);
  return OPAL_INT_TO_BOOL(ret);
}


inline void
MPI::Datatype::Get_contents(int max_integers, int max_addresses,
                            int max_datatypes, int array_of_integers[],
                            MPI::Aint array_of_addresses[],
                            MPI::Datatype array_of_datatypes[]) const
{
    int i;
    MPI_Datatype *c_datatypes = new MPI_Datatype[max_datatypes];

    (void) MPI_Type_get_contents(mpi_datatype, max_integers, max_addresses,
                                 max_datatypes,
                                 const_cast<int *>(array_of_integers),
                                 const_cast<MPI_Aint*>(array_of_addresses),
                                 c_datatypes);
    // Convert the C MPI_Datatypes to the user's OUT MPI::Datatype
    // array parameter
    for (i = 0; i < max_datatypes; ++i) {
        array_of_datatypes[i] = c_datatypes[i];
    }
    delete[] c_datatypes;
}

inline void
MPI::Datatype::Get_envelope(int& num_integers, int& num_addresses,
			  int& num_datatypes, int& combiner) const
{
  (void) MPI_Type_get_envelope(mpi_datatype, &num_integers, &num_addresses,
				&num_datatypes, &combiner);
}

inline void
MPI::Datatype::Get_name(char* type_name, int& resultlen) const
{
  (void) MPI_Type_get_name(mpi_datatype, type_name, &resultlen);
}

inline void
MPI::Datatype::Set_attr(int type_keyval, const void* attribute_val)
{
  (void) MPI_Type_set_attr(mpi_datatype, type_keyval, const_cast<void *>(attribute_val));
}

inline void
MPI::Datatype::Set_name(const char* type_name)
{
  (void) MPI_Type_set_name(mpi_datatype, const_cast<char *>(type_name));
}


#if 0
//
// User Defined Functions
//

typedef int MPI::Datatype::Copy_attr_function(const Datatype& oldtype,
						     int type_keyval,
						     void* extra_state,
						     void* attribute_val_in,
						     void* attribute_val_out,
						     bool& flag);

typedef int MPI::Datatype::Delete_attr_function(Datatype& type,
						       int type_keyval,
						       void* attribute_val,
						       void* extra_state);
#endif