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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* 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) 2007 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2018-2019 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
* All Rights reserved.
* Copyright (c) 2023 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file
*
* Implementation for taking care of the attribute that can hang off a comm,
* win or datatype.
*/
#ifndef OMPI_ATTRIBUTE_H
#define OMPI_ATTRIBUTE_H
#include <string.h>
#include "mpi.h"
#include "ompi_config.h"
#include "ompi/constants.h"
#include "opal/class/opal_object.h"
#include "opal/class/opal_hash_table.h"
#define ATTR_HASH_SIZE 10
/*
* Flags for keyvals
*/
#define OMPI_KEYVAL_PREDEFINED 0x0001
#define OMPI_KEYVAL_F77 0x0002
#define OMPI_KEYVAL_F77_INT 0x0004
BEGIN_C_DECLS
enum ompi_attribute_type_t {
UNUSED_ATTR = 0, /**< Make the compilers happy when we have to construct
* an attribute */
COMM_ATTR, /**< The attribute belongs to a comm object. Starts
* with 1 so that we can have it initialized to 0
* using memset in the constructor */
TYPE_ATTR, /**< The attribute belongs to datatype object */
WIN_ATTR, /**< The attribute belongs to a win object */
};
typedef enum ompi_attribute_type_t ompi_attribute_type_t;
/* Old-style MPI-1 Fortran function pointer declarations for copy and
delete. These will only be used here and not in the front end
functions. */
typedef void (*ompi_fint_copy_attr_function)(MPI_Fint *oldobj, MPI_Fint *keyval,
MPI_Fint *extra_state, MPI_Fint *attr_in,
MPI_Fint *attr_out, ompi_fortran_logical_t *flag,
MPI_Fint *ierr);
typedef void (*ompi_fint_delete_attr_function)(MPI_Fint *obj, MPI_Fint *keyval, MPI_Fint *attr_in,
MPI_Fint *extra_state, MPI_Fint *ierr);
/* New-style MPI-2 Fortran function pointer declarations for copy and
delete. These will only be used here and not in the front end
functions. */
typedef void (*ompi_aint_copy_attr_function)(MPI_Fint *oldobj, MPI_Fint *keyval, void *extra_state,
void *attr_in, void *attr_out,
ompi_fortran_logical_t *flag, MPI_Fint *ierr);
typedef void (*ompi_aint_delete_attr_function)(MPI_Fint *obj, MPI_Fint *keyval, void *attr_in,
void *extra_state, MPI_Fint *ierr);
typedef void (ompi_attribute_keyval_destructor_fn_t)(int);
/* Union to take care of proper casting of the function pointers
passed from the front end functions depending on the type. This
will avoid casting function pointers to void* */
union ompi_attribute_fn_ptr_union_t {
MPI_Comm_delete_attr_function *attr_communicator_delete_fn;
MPI_Type_delete_attr_function *attr_datatype_delete_fn;
MPI_Win_delete_attr_function *attr_win_delete_fn;
MPI_Comm_copy_attr_function *attr_communicator_copy_fn;
MPI_Type_copy_attr_function *attr_datatype_copy_fn;
MPI_Win_copy_attr_function *attr_win_copy_fn;
/* For Fortran old MPI-1 callback functions */
ompi_fint_delete_attr_function attr_fint_delete_fn;
ompi_fint_copy_attr_function attr_fint_copy_fn;
/* For Fortran new MPI-2 callback functions */
ompi_aint_delete_attr_function attr_aint_delete_fn;
ompi_aint_copy_attr_function attr_aint_copy_fn;
};
typedef union ompi_attribute_fn_ptr_union_t ompi_attribute_fn_ptr_union_t;
/**
* Union to help convert between Fortran attributes (which must be
* stored by value) and C pointers (which is the back-end storage of
* all attributes).
*/
union ompi_attribute_fortran_ptr_t {
void *c_ptr;
MPI_Fint f_integer;
MPI_Aint f_address;
};
/**
* Convenience typedef
*/
typedef union ompi_attribute_fortran_ptr_t ompi_attribute_fortran_ptr_t;
struct ompi_attribute_keyval_t {
opal_object_t super;
ompi_attribute_type_t attr_type; /**< One of COMM/WIN/DTYPE. This
will be used to cast the
copy/delete attribute functions
properly and error checking */
int attr_flag; /**< flag field: contains "OMPI_KEYVAL_PREDEFINED",
"OMPI_KEYVAL_F77" */
ompi_attribute_fn_ptr_union_t copy_attr_fn; /**< Copy function for the
attribute */
ompi_attribute_fn_ptr_union_t delete_attr_fn; /**< Delete function for the
attribute */
ompi_attribute_fortran_ptr_t extra_state; /**< Extra state of the attribute */
int key; /**< Keep a track of which key this item belongs to, so that
the key can be deleted when this object is destroyed */
/** Extra state for bindings to hang data on. If non-NULL, will be
freed by the C base when the keyval is destroyed. */
void *bindings_extra_state;
};
typedef struct ompi_attribute_keyval_t ompi_attribute_keyval_t;
/* Functions */
/**
* Convenient way to initialize the attribute hash table per MPI-Object
*/
static inline
int ompi_attr_hash_init(opal_hash_table_t **hash)
{
*hash = OBJ_NEW(opal_hash_table_t);
if (NULL == *hash) {
fprintf(stderr, "Error while creating the local attribute list\n");
return OMPI_ERR_OUT_OF_RESOURCE;
}
if (OMPI_SUCCESS != opal_hash_table_init(*hash, ATTR_HASH_SIZE)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
return MPI_SUCCESS;
}
/**
* Increase the reference count on the attributes subsystem. Instantiate subsys if
* not yet instantiated.
*
* @return OMPI return code
*/
int ompi_attr_get_ref(void);
/**
* Decrease the reference count on the attributes subsystem. Attributes subsystem
* resources are released when the count drops to zero.
*
* @return OMPI return code
*/
int ompi_attr_put_ref(void);
/**
* Create a new key for use by attribute of Comm/Win/Datatype/Instance
*
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param copy_attr_fn Union variable containing the function pointer
* to be used in order to copy the attribute (IN)
* @param delete_attr_fn Function pointer to be used for deleting the
* attribute (IN)
* @param key The newly created key is returned here (OUT)
* @param extra_state Extra state to hang off/do some special things (IN)
* @param flags Flags for the key -- flags contain OMPI_KEYVAL_F77,
* OMPI_KEYVAL_PREDEFINED
* @param bindings_extra_state Extra state that, if non-NULL, will
* automatically be free()'ed by the C base when
* the keyval is destroyed.
*
* NOTE: I have taken the assumption that user cannot modify/delete
* any predefined keys or the attributes attached. To accomplish this,
* all MPI* calls will have OMPI_KEYVAL_PREDEFINED set as 0. MPI
* implementors who will need to play with the predefined keys and
* attributes would call the ompi* functions here and not the MPI*
* functions, with OMPI_KEYVAL_PREDEFINED set to 1.
* END OF NOTE
*
* NOTE: For the function pointers, you need to create a variable of the
* union type "ompi_attribute_fn_ptr_union_t" and assign the proper field.
* to be passed into this function
* END OF NOTE
*
* @return OMPI return code
*
*/
OMPI_DECLSPEC int ompi_attr_create_keyval(ompi_attribute_type_t type,
ompi_attribute_fn_ptr_union_t copy_attr_fn,
ompi_attribute_fn_ptr_union_t delete_attr_fn,
int *key, void *extra_state, int flags,
void *bindings_extra_state);
/**
* Same as ompi_attr_create_keyval, but extra_state is a Fortran default integer.
*/
OMPI_DECLSPEC int ompi_attr_create_keyval_fint(ompi_attribute_type_t type,
ompi_attribute_fn_ptr_union_t copy_attr_fn,
ompi_attribute_fn_ptr_union_t delete_attr_fn,
int *key, MPI_Fint extra_state, int flags,
void *bindings_extra_state);
/**
* Same as ompi_attr_create_keyval, but extra_state is a Fortran address integer.
*/
OMPI_DECLSPEC int ompi_attr_create_keyval_aint(ompi_attribute_type_t type,
ompi_attribute_fn_ptr_union_t copy_attr_fn,
ompi_attribute_fn_ptr_union_t delete_attr_fn,
int *key, MPI_Aint extra_state, int flags,
void *bindings_extra_state);
/**
* Free an attribute keyval
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param key key, which is set to MPI_KEY_INVALID (IN/OUT)
* @return OMPI error code
*/
int ompi_attr_free_keyval(ompi_attribute_type_t type, int *key,
bool predefined);
/**
* Set an attribute on the comm/win/datatype in a form valid for C.
*
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The actual Comm/Win/Datatype/Instance object (IN)
* @param attr_hash The attribute hash table hanging on the object(IN/OUT)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (IN)
* @param predefined Whether the key is predefined or not 0/1 (IN)
* @return OMPI error code
*
* If (*attr_hash) == NULL, a new hash will be created and
* initialized.
*
* All four of these functions (ompi_attr_set_c(), ompi_attr_set_int(),
* ompi_attr_set_fint(), and ompi_attr_set_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
int ompi_attr_set_c(ompi_attribute_type_t type, void *object,
opal_hash_table_t **attr_hash,
int key, void *attribute, bool predefined);
/**
* Set an int predefined attribute in a form valid for C.
*
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The actual Comm/Win/Datatype/Instance object (IN)
* @param attr_hash The attribute hash table hanging on the object(IN/OUT)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute value (IN)
* @param predefined Whether the key is predefined or not 0/1 (IN)
* @return OMPI error code
*
* If (*attr_hash) == NULL, a new hash will be created and
* initialized.
*
* All four of these functions (ompi_attr_set_c(), ompi_attr_set_int(),
* ompi_attr_set_fint(), and ompi_attr_set_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
int ompi_attr_set_int(ompi_attribute_type_t type, void *object,
opal_hash_table_t **attr_hash,
int key, int attribute, bool predefined);
/**
* Set an attribute on the comm/win/datatype in a form valid for
* Fortran MPI-1.
*
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The actual Comm/Win/Datatype/Instance object (IN)
* @param attr_hash The attribute hash table hanging on the object(IN/OUT)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (IN)
* @param predefined Whether the key is predefined or not 0/1 (IN)
* @return OMPI error code
*
* If (*attr_hash) == NULL, a new hash will be created and
* initialized.
*
* All four of these functions (ompi_attr_set_c(), ompi_attr_set_int(),
* ompi_attr_set_fint(), and ompi_attr_set_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
OMPI_DECLSPEC int ompi_attr_set_fint(ompi_attribute_type_t type, void *object,
opal_hash_table_t **attr_hash,
int key, MPI_Fint attribute,
bool predefined);
/**
* Set an attribute on the comm/win/datatype in a form valid for
* Fortran MPI-2.
*
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The actual Comm/Win/Datatype/Instance object (IN)
* @param attr_hash The attribute hash table hanging on the object(IN/OUT)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (IN)
* @param predefined Whether the key is predefined or not 0/1 (IN)
* @return OMPI error code
*
* If (*attr_hash) == NULL, a new hash will be created and
* initialized.
*
* All four of these functions (ompi_attr_set_c(), ompi_attr_set_int(),
* ompi_attr_set_fint(), and ompi_attr_set_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
OMPI_DECLSPEC int ompi_attr_set_aint(ompi_attribute_type_t type, void *object,
opal_hash_table_t **attr_hash,
int key, MPI_Aint attribute,
bool predefined);
/**
* Get an attribute on the comm/win/datatype in a form valid for C.
*
* @param attr_hash The attribute hash table hanging on the object(IN)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (OUT)
* @param flag Flag whether an attribute is associated
* with the key (OUT)
* @return OMPI error code
*
* All three of these functions (ompi_attr_get_c(),
* ompi_attr_get_fint(), and ompi_attr_get_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
int ompi_attr_get_c(opal_hash_table_t *attr_hash, int key,
void **attribute, int *flag);
/**
* Get an attribute on the comm/win/datatype in a form valid for
* Fortran MPI-1.
*
* @param attr_hash The attribute hash table hanging on the object(IN)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (OUT)
* @param flag Flag whether an attribute is associated
* with the key (OUT)
* @return OMPI error code
*
* All three of these functions (ompi_attr_get_c(),
* ompi_attr_get_fint(), and ompi_attr_get_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
OMPI_DECLSPEC int ompi_attr_get_fint(opal_hash_table_t *attr_hash, int key,
MPI_Fint *attribute, int *flag);
/**
* Get an attribute on the comm/win/datatype in a form valid for
* Fortran MPI-2.
*
* @param attr_hash The attribute hash table hanging on the object(IN)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (OUT)
* @param flag Flag whether an attribute is associated
* with the key (OUT)
* @return OMPI error code
*
* All three of these functions (ompi_attr_get_c(),
* ompi_attr_get_fint(), and ompi_attr_get_aint())
* could have been combined into one function that took some kind of
* (void*) and an enum to indicate which way to translate the final
* representation, but that just seemed to make an already complicated
* situation more complicated through yet another layer of
* indirection.
*
* So yes, this is more code, but it's clearer and less error-prone
* (read: better) this way.
*/
OMPI_DECLSPEC int ompi_attr_get_aint(opal_hash_table_t *attr_hash, int key,
MPI_Aint *attribute, int *flag);
/**
* Delete an attribute on the comm/win/datatype
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The actual Comm/Win/Datatype/Instance object (IN)
* @param attr_hash The attribute hash table hanging on the object(IN)
* @param key Key val for the attribute (IN)
* @param predefined Whether the key is predefined or not 0/1 (IN)
* @return OMPI error code
*
*/
int ompi_attr_delete(ompi_attribute_type_t type, void *object,
opal_hash_table_t *attr_hash , int key,
bool predefined);
/**
* This to be used from functions like MPI_*_DUP in order to copy all
* the attributes from the old Comm/Win/Dtype/Instance object to a new
* object.
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param old_object The old COMM/WIN/DTYPE object (IN)
* @param new_object The new COMM/WIN/DTYPE object (IN)
* @param oldattr_hash The attribute hash table hanging on old object(IN)
* @param newattr_hash The attribute hash table hanging on new object(IN)
* @return OMPI error code
*
*/
int ompi_attr_copy_all(ompi_attribute_type_t type, void *old_object,
void *new_object, opal_hash_table_t *oldattr_hash,
opal_hash_table_t *newattr_hash);
/**
* This to be used to delete all the attributes from the Comm/Win/Dtype/Instance
* object in one shot
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The COMM/WIN/DTYPE object (IN)
* @param attr_hash The attribute hash table hanging on the object(IN)
* @return OMPI error code
*
*/
int ompi_attr_delete_all(ompi_attribute_type_t type, void *object,
opal_hash_table_t *attr_hash);
/**
* \internal
*
* Create all the predefined attribute keys
* @note This routine is invoked when creating a session
* so must be thread safe.
*
* @returns OMPI_SUCCESS
*/
int ompi_attr_create_predefined_keyvals(void);
/**
* \internal
*
* Cache and release the predefined attribute keys used in the World Model
*
* @returns OMPI_SUCCESS
*/
int ompi_attr_set_predefined_keyvals_for_wm(void);
void ompi_attr_delete_predefined_keyvals_for_wm(void);
/**
* \internal
*
* Free all the predefined attributes
*
* @returns OMPI_SUCCESS
*/
int ompi_attr_free_predefined(void);
END_C_DECLS
#endif /* OMPI_ATTRIBUTE_H */
|