[97] | 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 | |
---|
| 15 | // $COPYRIGHT$ |
---|
| 16 | // |
---|
| 17 | // Additional copyrights may follow |
---|
| 18 | // |
---|
| 19 | // $HEADER$ |
---|
| 20 | // |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | // |
---|
| 24 | // Point-to-Point Communication |
---|
| 25 | // |
---|
| 26 | |
---|
| 27 | inline MPI::Datatype |
---|
| 28 | MPI::Datatype::Create_contiguous(int count) const |
---|
| 29 | { |
---|
| 30 | MPI_Datatype newtype; |
---|
| 31 | (void)MPI_Type_contiguous(count, mpi_datatype, &newtype); |
---|
| 32 | return newtype; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | inline MPI::Datatype |
---|
| 36 | MPI::Datatype::Create_vector(int count, int blocklength, |
---|
| 37 | int stride) const |
---|
| 38 | { |
---|
| 39 | MPI_Datatype newtype; |
---|
| 40 | (void)MPI_Type_vector(count, blocklength, stride, mpi_datatype, &newtype); |
---|
| 41 | return newtype; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | inline MPI::Datatype |
---|
| 45 | MPI::Datatype::Create_indexed(int count, |
---|
| 46 | const int array_of_blocklengths[], |
---|
| 47 | const int array_of_displacements[]) const |
---|
| 48 | { |
---|
| 49 | MPI_Datatype newtype; |
---|
| 50 | (void)MPI_Type_indexed(count, const_cast<int *>(array_of_blocklengths), |
---|
| 51 | const_cast<int *>(array_of_displacements), mpi_datatype, &newtype); |
---|
| 52 | return newtype; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | inline MPI::Datatype |
---|
| 56 | MPI::Datatype::Create_struct(int count, const int array_of_blocklengths[], |
---|
| 57 | const MPI::Aint array_of_displacements[], |
---|
| 58 | const MPI::Datatype array_of_types[]) |
---|
| 59 | { |
---|
| 60 | MPI_Datatype newtype; |
---|
| 61 | int i; |
---|
| 62 | MPI_Datatype* type_array = new MPI_Datatype[count]; |
---|
| 63 | for (i=0; i < count; i++) |
---|
| 64 | type_array[i] = array_of_types[i]; |
---|
| 65 | |
---|
| 66 | (void)MPI_Type_create_struct(count, const_cast<int *>(array_of_blocklengths), |
---|
| 67 | const_cast<MPI_Aint*>(array_of_displacements), |
---|
| 68 | type_array, &newtype); |
---|
| 69 | delete[] type_array; |
---|
| 70 | return newtype; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | inline MPI::Datatype |
---|
| 74 | MPI::Datatype::Create_hindexed(int count, const int array_of_blocklengths[], |
---|
| 75 | const MPI::Aint array_of_displacements[]) const |
---|
| 76 | { |
---|
| 77 | MPI_Datatype newtype; |
---|
| 78 | (void)MPI_Type_create_hindexed(count, const_cast<int *>(array_of_blocklengths), |
---|
| 79 | const_cast<MPI_Aint*>(array_of_displacements), |
---|
| 80 | mpi_datatype, &newtype) ; |
---|
| 81 | return newtype; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | inline MPI::Datatype |
---|
| 85 | MPI::Datatype::Create_hvector(int count, int blocklength, |
---|
| 86 | MPI::Aint stride) const |
---|
| 87 | { |
---|
| 88 | MPI_Datatype newtype; |
---|
| 89 | (void)MPI_Type_create_hvector(count, blocklength, (MPI_Aint)stride, |
---|
| 90 | mpi_datatype, &newtype); |
---|
| 91 | |
---|
| 92 | return newtype; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | inline MPI::Datatype |
---|
| 96 | MPI::Datatype::Create_indexed_block(int count, int blocklength, |
---|
| 97 | const int array_of_displacements[]) const |
---|
| 98 | { |
---|
| 99 | MPI_Datatype newtype; |
---|
| 100 | (void)MPI_Type_create_indexed_block(count, blocklength, const_cast<int *>(array_of_displacements), |
---|
| 101 | mpi_datatype, &newtype); |
---|
| 102 | return newtype; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | inline MPI::Datatype |
---|
| 106 | MPI::Datatype::Create_resized(const MPI::Aint lb, const MPI::Aint extent) const |
---|
| 107 | { |
---|
| 108 | MPI_Datatype newtype; |
---|
| 109 | |
---|
| 110 | (void) MPI_Type_create_resized(mpi_datatype, lb, extent, &newtype); |
---|
| 111 | return(newtype); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | inline int |
---|
| 115 | MPI::Datatype::Get_size() const |
---|
| 116 | { |
---|
| 117 | int size; |
---|
| 118 | (void)MPI_Type_size(mpi_datatype, &size); |
---|
| 119 | return size; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | inline void |
---|
| 123 | MPI::Datatype::Get_extent(MPI::Aint& lb, MPI::Aint& extent) const |
---|
| 124 | { |
---|
| 125 | (void)MPI_Type_get_extent(mpi_datatype, &lb, &extent); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | inline void |
---|
| 129 | MPI::Datatype::Get_true_extent(MPI::Aint& lb, MPI::Aint& extent) const |
---|
| 130 | { |
---|
| 131 | (void) MPI_Type_get_true_extent(mpi_datatype, &lb, &extent); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | inline void |
---|
| 135 | MPI::Datatype::Commit() |
---|
| 136 | { |
---|
| 137 | (void)MPI_Type_commit(&mpi_datatype); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | inline void |
---|
| 141 | MPI::Datatype::Pack(const void* inbuf, int incount, |
---|
| 142 | void *outbuf, int outsize, |
---|
| 143 | int& position, const MPI::Comm &comm) const |
---|
| 144 | { |
---|
| 145 | (void)MPI_Pack(const_cast<void *>(inbuf), incount, mpi_datatype, outbuf, |
---|
| 146 | outsize, &position, comm); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | inline void |
---|
| 150 | MPI::Datatype::Unpack(const void* inbuf, int insize, |
---|
| 151 | void *outbuf, int outcount, int& position, |
---|
| 152 | const MPI::Comm& comm) const |
---|
| 153 | { |
---|
| 154 | (void)MPI_Unpack(const_cast<void *>(inbuf), insize, &position, |
---|
| 155 | outbuf, outcount, mpi_datatype, comm); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | inline int |
---|
| 159 | MPI::Datatype::Pack_size(int incount, const MPI::Comm& comm) const |
---|
| 160 | { |
---|
| 161 | int size; |
---|
| 162 | (void)MPI_Pack_size(incount, mpi_datatype, comm, &size); |
---|
| 163 | return size; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | // |
---|
| 168 | // Miscellany |
---|
| 169 | // |
---|
| 170 | |
---|
| 171 | inline MPI::Datatype |
---|
| 172 | MPI::Datatype::Create_subarray(int ndims, const int array_of_sizes[], |
---|
| 173 | const int array_of_subsizes[], |
---|
| 174 | const int array_of_starts[], int order) |
---|
| 175 | const |
---|
| 176 | { |
---|
| 177 | MPI_Datatype type; |
---|
| 178 | (void) MPI_Type_create_subarray(ndims, const_cast<int *>(array_of_sizes), |
---|
| 179 | const_cast<int *>(array_of_subsizes), |
---|
| 180 | const_cast<int *>(array_of_starts), |
---|
| 181 | order, mpi_datatype, &type); |
---|
| 182 | return type; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | // |
---|
| 187 | // External Interfaces |
---|
| 188 | // |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | inline MPI::Datatype |
---|
| 192 | MPI::Datatype::Dup() const |
---|
| 193 | { |
---|
| 194 | MPI_Datatype type; |
---|
| 195 | (void) MPI_Type_dup(mpi_datatype, &type); |
---|
| 196 | return type; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | // 1) original Create_keyval that takes the first 2 arguments as C++ |
---|
| 201 | // functions |
---|
| 202 | inline int |
---|
| 203 | MPI::Datatype::Create_keyval(MPI::Datatype::Copy_attr_function* type_copy_attr_fn, |
---|
| 204 | MPI::Datatype::Delete_attr_function* type_delete_attr_fn, |
---|
| 205 | void* extra_state) |
---|
| 206 | { |
---|
| 207 | // Back-end function does the heavy lifting |
---|
| 208 | int ret, keyval; |
---|
| 209 | ret = do_create_keyval(NULL, NULL, |
---|
| 210 | type_copy_attr_fn, type_delete_attr_fn, |
---|
| 211 | extra_state, keyval); |
---|
| 212 | return (MPI_SUCCESS == ret) ? keyval : ret; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | // 2) overload Create_keyval to take the first 2 arguments as C |
---|
| 216 | // functions |
---|
| 217 | inline int |
---|
| 218 | MPI::Datatype::Create_keyval(MPI_Type_copy_attr_function* type_copy_attr_fn, |
---|
| 219 | MPI_Type_delete_attr_function* type_delete_attr_fn, |
---|
| 220 | void* extra_state) |
---|
| 221 | { |
---|
| 222 | // Back-end function does the heavy lifting |
---|
| 223 | int ret, keyval; |
---|
| 224 | ret = do_create_keyval(type_copy_attr_fn, type_delete_attr_fn, |
---|
| 225 | NULL, NULL, |
---|
| 226 | extra_state, keyval); |
---|
| 227 | return (MPI_SUCCESS == ret) ? keyval : ret; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | // 3) overload Create_keyval to take the first 2 arguments as C++ & C |
---|
| 231 | // functions |
---|
| 232 | inline int |
---|
| 233 | MPI::Datatype::Create_keyval(MPI::Datatype::Copy_attr_function* type_copy_attr_fn, |
---|
| 234 | MPI_Type_delete_attr_function* type_delete_attr_fn, |
---|
| 235 | void* extra_state) |
---|
| 236 | { |
---|
| 237 | // Back-end function does the heavy lifting |
---|
| 238 | int ret, keyval; |
---|
| 239 | ret = do_create_keyval(NULL, type_delete_attr_fn, |
---|
| 240 | type_copy_attr_fn, NULL, |
---|
| 241 | extra_state, keyval); |
---|
| 242 | return (MPI_SUCCESS == ret) ? keyval : ret; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | // 4) overload Create_keyval to take the first 2 arguments as C & C++ |
---|
| 246 | // functions |
---|
| 247 | inline int |
---|
| 248 | MPI::Datatype::Create_keyval(MPI_Type_copy_attr_function* type_copy_attr_fn, |
---|
| 249 | MPI::Datatype::Delete_attr_function* type_delete_attr_fn, |
---|
| 250 | void* extra_state) |
---|
| 251 | { |
---|
| 252 | // Back-end function does the heavy lifting |
---|
| 253 | int ret, keyval; |
---|
| 254 | ret = do_create_keyval(type_copy_attr_fn, NULL, |
---|
| 255 | NULL, type_delete_attr_fn, |
---|
| 256 | extra_state, keyval); |
---|
| 257 | return (MPI_SUCCESS == ret) ? keyval : ret; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | inline void |
---|
| 261 | MPI::Datatype::Delete_attr(int type_keyval) |
---|
| 262 | { |
---|
| 263 | (void) MPI_Type_delete_attr(mpi_datatype, type_keyval); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | inline void |
---|
| 267 | MPI::Datatype::Free_keyval(int& type_keyval) |
---|
| 268 | { |
---|
| 269 | (void) MPI_Type_free_keyval(&type_keyval); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | inline bool |
---|
| 273 | MPI::Datatype::Get_attr(int type_keyval, |
---|
| 274 | void* attribute_val) const |
---|
| 275 | { |
---|
| 276 | int ret; |
---|
| 277 | (void) MPI_Type_get_attr(mpi_datatype, type_keyval, attribute_val, &ret); |
---|
| 278 | return OPAL_INT_TO_BOOL(ret); |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | inline void |
---|
| 283 | MPI::Datatype::Get_contents(int max_integers, int max_addresses, |
---|
| 284 | int max_datatypes, int array_of_integers[], |
---|
| 285 | MPI::Aint array_of_addresses[], |
---|
| 286 | MPI::Datatype array_of_datatypes[]) const |
---|
| 287 | { |
---|
| 288 | int i; |
---|
| 289 | MPI_Datatype *c_datatypes = new MPI_Datatype[max_datatypes]; |
---|
| 290 | |
---|
| 291 | (void) MPI_Type_get_contents(mpi_datatype, max_integers, max_addresses, |
---|
| 292 | max_datatypes, |
---|
| 293 | const_cast<int *>(array_of_integers), |
---|
| 294 | const_cast<MPI_Aint*>(array_of_addresses), |
---|
| 295 | c_datatypes); |
---|
| 296 | // Convert the C MPI_Datatypes to the user's OUT MPI::Datatype |
---|
| 297 | // array parameter |
---|
| 298 | for (i = 0; i < max_datatypes; ++i) { |
---|
| 299 | array_of_datatypes[i] = c_datatypes[i]; |
---|
| 300 | } |
---|
| 301 | delete[] c_datatypes; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | inline void |
---|
| 305 | MPI::Datatype::Get_envelope(int& num_integers, int& num_addresses, |
---|
| 306 | int& num_datatypes, int& combiner) const |
---|
| 307 | { |
---|
| 308 | (void) MPI_Type_get_envelope(mpi_datatype, &num_integers, &num_addresses, |
---|
| 309 | &num_datatypes, &combiner); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | inline void |
---|
| 313 | MPI::Datatype::Get_name(char* type_name, int& resultlen) const |
---|
| 314 | { |
---|
| 315 | (void) MPI_Type_get_name(mpi_datatype, type_name, &resultlen); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | inline void |
---|
| 319 | MPI::Datatype::Set_attr(int type_keyval, const void* attribute_val) |
---|
| 320 | { |
---|
| 321 | (void) MPI_Type_set_attr(mpi_datatype, type_keyval, const_cast<void *>(attribute_val)); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | inline void |
---|
| 325 | MPI::Datatype::Set_name(const char* type_name) |
---|
| 326 | { |
---|
| 327 | (void) MPI_Type_set_name(mpi_datatype, const_cast<char *>(type_name)); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | #if 0 |
---|
| 332 | // |
---|
| 333 | // User Defined Functions |
---|
| 334 | // |
---|
| 335 | |
---|
| 336 | typedef int MPI::Datatype::Copy_attr_function(const Datatype& oldtype, |
---|
| 337 | int type_keyval, |
---|
| 338 | void* extra_state, |
---|
| 339 | void* attribute_val_in, |
---|
| 340 | void* attribute_val_out, |
---|
| 341 | bool& flag); |
---|
| 342 | |
---|
| 343 | typedef int MPI::Datatype::Delete_attr_function(Datatype& type, |
---|
| 344 | int type_keyval, |
---|
| 345 | void* attribute_val, |
---|
| 346 | void* extra_state); |
---|
| 347 | #endif |
---|