root/ompi/mpi/cxx/datatype_inln.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. Create_contiguous
  2. Create_vector
  3. Create_indexed
  4. Create_struct
  5. Create_hindexed
  6. Create_hvector
  7. Create_indexed_block
  8. Create_resized
  9. Get_size
  10. Get_extent
  11. Get_true_extent
  12. Commit
  13. Pack
  14. Unpack
  15. Pack_size
  16. Pack_external
  17. Pack_external_size
  18. Unpack_external
  19. Create_subarray
  20. Create_darray
  21. Create_f90_complex
  22. Create_f90_integer
  23. Create_f90_real
  24. Match_size
  25. Dup
  26. Create_keyval
  27. Create_keyval
  28. Create_keyval
  29. Create_keyval
  30. Delete_attr
  31. Free_keyval
  32. Get_attr
  33. Get_contents
  34. Get_envelope
  35. Get_name
  36. Set_attr
  37. Set_name

   1 // -*- c++ -*-
   2 //
   3 // Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4 //                         University Research and Technology
   5 //                         Corporation.  All rights reserved.
   6 // Copyright (c) 2004-2005 The University of Tennessee and The University
   7 //                         of Tennessee Research Foundation.  All rights
   8 //                         reserved.
   9 // Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10 //                         University of Stuttgart.  All rights reserved.
  11 // Copyright (c) 2004-2005 The Regents of the University of California.
  12 //                         All rights reserved.
  13 // Copyright (c) 2006-2008 Sun Microsystems, Inc.  All rights reserved.
  14 // Copyright (c) 2011      FUJITSU LIMITED.  All rights reserved.
  15 
  16 // $COPYRIGHT$
  17 //
  18 // Additional copyrights may follow
  19 //
  20 // $HEADER$
  21 //
  22 
  23 
  24 //
  25 // Point-to-Point Communication
  26 //
  27 
  28 inline MPI::Datatype
  29 MPI::Datatype::Create_contiguous(int count) const
  30 {
  31   MPI_Datatype newtype;
  32   (void)MPI_Type_contiguous(count, mpi_datatype, &newtype);
  33   return newtype;
  34 }
  35 
  36 inline MPI::Datatype
  37 MPI::Datatype::Create_vector(int count, int blocklength,
  38                              int stride) const
  39 {
  40   MPI_Datatype newtype;
  41   (void)MPI_Type_vector(count, blocklength, stride, mpi_datatype, &newtype);
  42   return newtype;
  43 }
  44 
  45 inline MPI::Datatype
  46 MPI::Datatype::Create_indexed(int count,
  47                                      const int array_of_blocklengths[],
  48                                      const int array_of_displacements[]) const
  49 {
  50   MPI_Datatype newtype;
  51   (void)MPI_Type_indexed(count, const_cast<int *>(array_of_blocklengths),
  52                          const_cast<int *>(array_of_displacements), mpi_datatype, &newtype);
  53   return newtype;
  54 }
  55 
  56 inline MPI::Datatype
  57 MPI::Datatype::Create_struct(int count, const int array_of_blocklengths[],
  58                                     const MPI::Aint array_of_displacements[],
  59                                     const MPI::Datatype array_of_types[])
  60 {
  61   MPI_Datatype newtype;
  62   int i;
  63   MPI_Datatype* type_array = new MPI_Datatype[count];
  64   for (i=0; i < count; i++)
  65     type_array[i] = array_of_types[i];
  66 
  67   (void)MPI_Type_create_struct(count, const_cast<int *>(array_of_blocklengths),
  68                                const_cast<MPI_Aint*>(array_of_displacements),
  69                                type_array, &newtype);
  70   delete[] type_array;
  71   return newtype;
  72 }
  73 
  74 inline MPI::Datatype
  75 MPI::Datatype::Create_hindexed(int count, const int array_of_blocklengths[],
  76                                       const MPI::Aint array_of_displacements[]) const
  77 {
  78   MPI_Datatype newtype;
  79   (void)MPI_Type_create_hindexed(count, const_cast<int *>(array_of_blocklengths),
  80                                  const_cast<MPI_Aint*>(array_of_displacements),
  81                                  mpi_datatype, &newtype) ;
  82   return newtype;
  83 }
  84 
  85 inline MPI::Datatype
  86 MPI::Datatype::Create_hvector(int count, int blocklength,
  87                                      MPI::Aint stride) const
  88 {
  89   MPI_Datatype newtype;
  90   (void)MPI_Type_create_hvector(count, blocklength, (MPI_Aint)stride,
  91                                 mpi_datatype, &newtype);
  92 
  93   return newtype;
  94 }
  95 
  96 inline MPI::Datatype
  97 MPI::Datatype::Create_indexed_block(int count, int blocklength,
  98                                     const int array_of_displacements[]) const
  99 {
 100   MPI_Datatype newtype;
 101   (void)MPI_Type_create_indexed_block(count, blocklength, const_cast<int *>(array_of_displacements),
 102                                       mpi_datatype, &newtype);
 103   return newtype;
 104 }
 105 
 106 inline MPI::Datatype
 107 MPI::Datatype::Create_resized(const MPI::Aint lb, const MPI::Aint extent) const
 108 {
 109     MPI_Datatype newtype;
 110 
 111     (void) MPI_Type_create_resized(mpi_datatype, lb, extent, &newtype);
 112     return(newtype);
 113 }
 114 
 115 inline int
 116 MPI::Datatype::Get_size() const
 117 {
 118   int size;
 119   (void)MPI_Type_size(mpi_datatype, &size);
 120   return size;
 121 }
 122 
 123 inline void
 124 MPI::Datatype::Get_extent(MPI::Aint& lb, MPI::Aint& extent) const
 125 {
 126   (void)MPI_Type_get_extent(mpi_datatype, &lb, &extent);
 127 }
 128 
 129 inline void
 130 MPI::Datatype::Get_true_extent(MPI::Aint& lb, MPI::Aint& extent) const
 131 {
 132     (void) MPI_Type_get_true_extent(mpi_datatype, &lb, &extent);
 133 }
 134 
 135 inline void
 136 MPI::Datatype::Commit()
 137 {
 138   (void)MPI_Type_commit(&mpi_datatype);
 139 }
 140 
 141 inline void
 142 MPI::Datatype::Pack(const void* inbuf, int incount,
 143                            void *outbuf, int outsize,
 144                            int& position, const MPI::Comm &comm) const
 145 {
 146   (void)MPI_Pack(const_cast<void *>(inbuf), incount,  mpi_datatype, outbuf,
 147                  outsize, &position, comm);
 148 }
 149 
 150 inline void
 151 MPI::Datatype::Unpack(const void* inbuf, int insize,
 152                              void *outbuf, int outcount, int& position,
 153                              const MPI::Comm& comm) const
 154 {
 155   (void)MPI_Unpack(const_cast<void *>(inbuf), insize, &position,
 156                    outbuf, outcount, mpi_datatype, comm);
 157 }
 158 
 159 inline int
 160 MPI::Datatype::Pack_size(int incount, const MPI::Comm& comm) const
 161 {
 162   int size;
 163   (void)MPI_Pack_size(incount, mpi_datatype, comm, &size);
 164   return size;
 165 }
 166 
 167 inline void
 168 MPI::Datatype::Pack_external(const char* datarep, const void* inbuf, int incount,
 169             void* outbuf, MPI::Aint outsize, MPI::Aint& position) const
 170 {
 171     (void)MPI_Pack_external(const_cast<char *>(datarep), const_cast<void *>(inbuf),
 172                              incount, mpi_datatype, outbuf, outsize, &position);
 173 }
 174 
 175 inline MPI::Aint
 176 MPI::Datatype::Pack_external_size(const char* datarep, int incount) const
 177 {
 178     MPI_Aint addr;
 179     (void)MPI_Pack_external_size(const_cast<char *>(datarep), incount, mpi_datatype, &addr);
 180     return addr;
 181 }
 182 
 183 inline void
 184 MPI::Datatype::Unpack_external(const char* datarep, const void* inbuf,
 185             MPI::Aint insize, MPI::Aint& position, void* outbuf, int outcount) const
 186 {
 187     (void)MPI_Unpack_external(const_cast<char *>(datarep), const_cast<void *>(inbuf),
 188                                insize, &position, outbuf, outcount, mpi_datatype);
 189 }
 190 
 191 //
 192 // Miscellany
 193 //
 194 
 195 inline MPI::Datatype
 196 MPI::Datatype::Create_subarray(int ndims, const int array_of_sizes[],
 197                                       const int array_of_subsizes[],
 198                                       const int array_of_starts[], int order)
 199   const
 200 {
 201   MPI_Datatype type;
 202   (void) MPI_Type_create_subarray(ndims, const_cast<int *>(array_of_sizes),
 203                                   const_cast<int *>(array_of_subsizes),
 204                                   const_cast<int *>(array_of_starts),
 205                                   order, mpi_datatype, &type);
 206   return type;
 207 }
 208 
 209 inline MPI::Datatype
 210 MPI::Datatype::Create_darray(int size, int rank, int ndims,
 211                    const int array_of_gsizes[], const int array_of_distribs[],
 212                    const int array_of_dargs[],  const int array_of_psizes[],
 213                    int order) const
 214 {
 215     MPI_Datatype type;
 216     (void) MPI_Type_create_darray(size, rank, ndims,
 217                    const_cast<int *>(array_of_gsizes),
 218                    const_cast<int *>(array_of_distribs),
 219                    const_cast<int *>(array_of_dargs),
 220                    const_cast<int *>(array_of_psizes),
 221                    order, mpi_datatype, &type);
 222     return type;
 223 }
 224 
 225 inline MPI::Datatype
 226 MPI::Datatype::Create_f90_complex(int p, int r)
 227 {
 228     MPI_Datatype type;
 229     (void) MPI_Type_create_f90_complex(p, r, &type);
 230     return type;
 231 }
 232 
 233 inline MPI::Datatype
 234 MPI::Datatype::Create_f90_integer(int r)
 235 {
 236     MPI_Datatype type;
 237     (void) MPI_Type_create_f90_integer(r, &type);
 238     return type;
 239 }
 240 
 241 inline MPI::Datatype
 242 MPI::Datatype::Create_f90_real(int p, int r)
 243 {
 244     MPI_Datatype type;
 245     (void) MPI_Type_create_f90_real(p, r, &type);
 246     return type;
 247 }
 248 
 249 inline MPI::Datatype
 250 MPI::Datatype::Match_size(int typeclass, int size)
 251 {
 252     MPI_Datatype type;
 253     (void) MPI_Type_match_size(typeclass, size, &type);
 254     return type;
 255 }
 256 
 257 //
 258 // External Interfaces
 259 //
 260 
 261 
 262 inline MPI::Datatype
 263 MPI::Datatype::Dup() const
 264 {
 265   MPI_Datatype type;
 266   (void) MPI_Type_dup(mpi_datatype, &type);
 267   return type;
 268 }
 269 
 270 
 271 // 1) original Create_keyval that takes the first 2 arguments as C++
 272 //    functions
 273 inline int
 274 MPI::Datatype::Create_keyval(MPI::Datatype::Copy_attr_function* type_copy_attr_fn,
 275                              MPI::Datatype::Delete_attr_function* type_delete_attr_fn,
 276                              void* extra_state)
 277 {
 278     // Back-end function does the heavy lifting
 279     int ret, keyval;
 280     ret = do_create_keyval(NULL, NULL,
 281                            type_copy_attr_fn, type_delete_attr_fn,
 282                            extra_state, keyval);
 283     return (MPI_SUCCESS == ret) ? keyval : ret;
 284 }
 285 
 286 // 2) overload Create_keyval to take the first 2 arguments as C
 287 //    functions
 288 inline int
 289 MPI::Datatype::Create_keyval(MPI_Type_copy_attr_function* type_copy_attr_fn,
 290                              MPI_Type_delete_attr_function* type_delete_attr_fn,
 291                              void* extra_state)
 292 {
 293     // Back-end function does the heavy lifting
 294     int ret, keyval;
 295     ret = do_create_keyval(type_copy_attr_fn, type_delete_attr_fn,
 296                            NULL, NULL,
 297                            extra_state, keyval);
 298     return (MPI_SUCCESS == ret) ? keyval : ret;
 299 }
 300 
 301 // 3) overload Create_keyval to take the first 2 arguments as C++ & C
 302 //    functions
 303 inline int
 304 MPI::Datatype::Create_keyval(MPI::Datatype::Copy_attr_function* type_copy_attr_fn,
 305                              MPI_Type_delete_attr_function* type_delete_attr_fn,
 306                              void* extra_state)
 307 {
 308     // Back-end function does the heavy lifting
 309     int ret, keyval;
 310     ret = do_create_keyval(NULL, type_delete_attr_fn,
 311                            type_copy_attr_fn, NULL,
 312                            extra_state, keyval);
 313     return (MPI_SUCCESS == ret) ? keyval : ret;
 314 }
 315 
 316 // 4) overload Create_keyval to take the first 2 arguments as C & C++
 317 //    functions
 318 inline int
 319 MPI::Datatype::Create_keyval(MPI_Type_copy_attr_function* type_copy_attr_fn,
 320                              MPI::Datatype::Delete_attr_function* type_delete_attr_fn,
 321                              void* extra_state)
 322 {
 323     // Back-end function does the heavy lifting
 324     int ret, keyval;
 325     ret = do_create_keyval(type_copy_attr_fn, NULL,
 326                            NULL, type_delete_attr_fn,
 327                            extra_state, keyval);
 328     return (MPI_SUCCESS == ret) ? keyval : ret;
 329 }
 330 
 331 inline void
 332 MPI::Datatype::Delete_attr(int type_keyval)
 333 {
 334   (void) MPI_Type_delete_attr(mpi_datatype, type_keyval);
 335 }
 336 
 337 inline void
 338 MPI::Datatype::Free_keyval(int& type_keyval)
 339 {
 340     (void) MPI_Type_free_keyval(&type_keyval);
 341 }
 342 
 343 inline bool
 344 MPI::Datatype::Get_attr(int type_keyval,
 345                           void* attribute_val) const
 346 {
 347   int ret;
 348   (void) MPI_Type_get_attr(mpi_datatype, type_keyval, attribute_val, &ret);
 349   return OPAL_INT_TO_BOOL(ret);
 350 }
 351 
 352 
 353 inline void
 354 MPI::Datatype::Get_contents(int max_integers, int max_addresses,
 355                             int max_datatypes, int array_of_integers[],
 356                             MPI::Aint array_of_addresses[],
 357                             MPI::Datatype array_of_datatypes[]) const
 358 {
 359     int i;
 360     MPI_Datatype *c_datatypes = new MPI_Datatype[max_datatypes];
 361 
 362     (void) MPI_Type_get_contents(mpi_datatype, max_integers, max_addresses,
 363                                  max_datatypes,
 364                                  const_cast<int *>(array_of_integers),
 365                                  const_cast<MPI_Aint*>(array_of_addresses),
 366                                  c_datatypes);
 367     // Convert the C MPI_Datatypes to the user's OUT MPI::Datatype
 368     // array parameter
 369     for (i = 0; i < max_datatypes; ++i) {
 370         array_of_datatypes[i] = c_datatypes[i];
 371     }
 372     delete[] c_datatypes;
 373 }
 374 
 375 inline void
 376 MPI::Datatype::Get_envelope(int& num_integers, int& num_addresses,
 377                           int& num_datatypes, int& combiner) const
 378 {
 379   (void) MPI_Type_get_envelope(mpi_datatype, &num_integers, &num_addresses,
 380                                 &num_datatypes, &combiner);
 381 }
 382 
 383 inline void
 384 MPI::Datatype::Get_name(char* type_name, int& resultlen) const
 385 {
 386   (void) MPI_Type_get_name(mpi_datatype, type_name, &resultlen);
 387 }
 388 
 389 inline void
 390 MPI::Datatype::Set_attr(int type_keyval, const void* attribute_val)
 391 {
 392   (void) MPI_Type_set_attr(mpi_datatype, type_keyval, const_cast<void *>(attribute_val));
 393 }
 394 
 395 inline void
 396 MPI::Datatype::Set_name(const char* type_name)
 397 {
 398   (void) MPI_Type_set_name(mpi_datatype, const_cast<char *>(type_name));
 399 }
 400 
 401 
 402 #if 0
 403 //
 404 // User Defined Functions
 405 //
 406 
 407 typedef int MPI::Datatype::Copy_attr_function(const Datatype& oldtype,
 408                                                      int type_keyval,
 409                                                      void* extra_state,
 410                                                      void* attribute_val_in,
 411                                                      void* attribute_val_out,
 412                                                      bool& flag);
 413 
 414 typedef int MPI::Datatype::Delete_attr_function(Datatype& type,
 415                                                        int type_keyval,
 416                                                        void* attribute_val,
 417                                                        void* extra_state);
 418 #endif

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