/* FIXME: Missing routine description */ void MPII_Keyval_set_proxy(int keyval, MPII_Attr_copy_proxy copy_proxy, MPII_Attr_delete_proxy delete_proxy) { MPII_Keyval *keyval_ptr; MPII_Keyval_get_ptr(keyval, keyval_ptr); if (keyval_ptr == NULL) return; keyval_ptr->copyfn.proxy = copy_proxy; keyval_ptr->delfn.proxy = delete_proxy; }
/*@ MPI_Comm_delete_attr - Deletes an attribute value associated with a key on a communicator Input Parameters: + comm - communicator to which attribute is attached (handle) - comm_keyval - The key value of the deleted attribute (integer) .N ThreadSafe .N Fortran .N Errors .N MPI_SUCCESS .N MPI_ERR_COMM .N MPI_ERR_PERM_KEY .seealso MPI_Comm_set_attr, MPI_Comm_create_keyval @*/ int MPI_Comm_delete_attr(MPI_Comm comm, int comm_keyval) { int mpi_errno = MPI_SUCCESS; MPIR_Comm *comm_ptr = NULL; MPII_Keyval *keyval_ptr; MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_COMM_DELETE_ATTR); MPIR_ERRTEST_INITIALIZED_ORDIE(); MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_COMM_DELETE_ATTR); /* Validate parameters, especially handles needing to be converted */ #ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { MPIR_ERRTEST_COMM(comm, mpi_errno); MPIR_ERRTEST_KEYVAL(comm_keyval, MPIR_COMM, "communicator", mpi_errno); MPIR_ERRTEST_KEYVAL_PERM(comm_keyval, mpi_errno); } MPID_END_ERROR_CHECKS; } #endif /* Convert MPI object handles to object pointers */ MPIR_Comm_get_ptr(comm, comm_ptr); MPII_Keyval_get_ptr(comm_keyval, keyval_ptr); /* Validate parameters and objects (post conversion) */ #ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { /* Validate comm_ptr */ MPIR_Comm_valid_ptr(comm_ptr, mpi_errno, TRUE); /* If comm_ptr is not valid, it will be reset to null */ /* Validate keyval_ptr */ MPII_Keyval_valid_ptr(keyval_ptr, mpi_errno); if (mpi_errno) goto fn_fail; } MPID_END_ERROR_CHECKS; } #endif /* HAVE_ERROR_CHECKING */ /* ... body of routine ... */ mpi_errno = MPIR_Comm_delete_attr_impl(comm_ptr, keyval_ptr); if (mpi_errno) goto fn_fail; /* ... end of body of routine ... */ fn_exit: MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_COMM_DELETE_ATTR); MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); return mpi_errno; fn_fail: /* --BEGIN ERROR HANDLING-- */ #ifdef HAVE_ERROR_CHECKING { mpi_errno = MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER, "**mpi_comm_delete_attr", "**mpi_comm_delete_attr %C %d", comm, comm_keyval); } #endif mpi_errno = MPIR_Err_return_comm(comm_ptr, __func__, mpi_errno); goto fn_exit; /* --END ERROR HANDLING-- */ }
int MPIR_Comm_set_attr_impl(MPIR_Comm * comm_ptr, int comm_keyval, void *attribute_val, MPIR_Attr_type attrType) { int mpi_errno = MPI_SUCCESS; MPII_Keyval *keyval_ptr = NULL; MPIR_Attribute *p; MPIR_ERR_CHKANDJUMP(comm_keyval == MPI_KEYVAL_INVALID, mpi_errno, MPI_ERR_KEYVAL, "**keyvalinvalid"); /* CHANGE FOR MPI 2.2: Look for attribute. They are ordered by when they * were added, with the most recent first. This uses * a simple linear list algorithm because few applications use more than a * handful of attributes */ MPII_Keyval_get_ptr(comm_keyval, keyval_ptr); MPIR_Assert(keyval_ptr != NULL); /* printf("Setting attr val to %x\n", attribute_val); */ p = comm_ptr->attributes; while (p) { if (p->keyval->handle == keyval_ptr->handle) { /* If found, call the delete function before replacing the * attribute */ mpi_errno = MPIR_Call_attr_delete(comm_ptr->handle, p); if (mpi_errno) { goto fn_fail; } p->attrType = attrType; /* FIXME: This code is incorrect in some cases, particularly * in the case where intptr_t is different from MPI_Aint, * since in that case, the Fortran 9x interface will provide * more bytes in the attribute_val than this allows. The * dual casts are a sign that this is faulty. This will * need to be fixed in the type/win set_attr routines as * well. */ p->value = (MPII_Attr_val_t) (intptr_t) attribute_val; /* printf("Updating attr at %x\n", &p->value); */ /* Does not change the reference count on the keyval */ break; } p = p->next; } /* CHANGE FOR MPI 2.2: If not found, add at the beginning */ if (!p) { MPIR_Attribute *new_p = MPID_Attr_alloc(); MPIR_ERR_CHKANDJUMP(!new_p, mpi_errno, MPI_ERR_OTHER, "**nomem"); /* Did not find in list. Add at end */ new_p->keyval = keyval_ptr; new_p->attrType = attrType; new_p->pre_sentinal = 0; /* FIXME: See the comment above on this dual cast. */ new_p->value = (MPII_Attr_val_t) (intptr_t) attribute_val; new_p->post_sentinal = 0; new_p->next = comm_ptr->attributes; MPII_Keyval_add_ref(keyval_ptr); comm_ptr->attributes = new_p; /* printf("Creating attr at %x\n", &new_p->value); */ } /* Here is where we could add a hook for the device to detect attribute * value changes, using something like * MPID_Comm_attr_hook(comm_ptr, keyval, attribute_val); */ fn_exit: return mpi_errno; fn_fail: goto fn_exit; }
/*@ MPI_Win_free_keyval - Frees an attribute key for MPI RMA windows Input Parameters: . win_keyval - key value (integer) .N ThreadSafe .N Fortran .N Errors .N MPI_SUCCESS .N MPI_ERR_WIN .N MPI_ERR_OTHER .N MPI_ERR_KEYVAL @*/ int MPI_Win_free_keyval(int *win_keyval) { #ifdef HAVE_ERROR_CHECKING static const char FCNAME[] = "MPI_Win_free_keyval"; #endif int mpi_errno = MPI_SUCCESS; MPII_Keyval *keyval_ptr = NULL; int in_use; MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_WIN_FREE_KEYVAL); MPIR_ERRTEST_INITIALIZED_ORDIE(); MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_WIN_FREE_KEYVAL); /* Validate parameters, especially handles needing to be converted */ # ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { MPIR_ERRTEST_ARGNULL(*win_keyval, "win_keyval", mpi_errno); MPIR_ERRTEST_KEYVAL(*win_keyval, MPIR_WIN, "window", mpi_errno); MPIR_ERRTEST_KEYVAL_PERM(*win_keyval, mpi_errno); } MPID_END_ERROR_CHECKS; } # endif /* Convert MPI object handles to object pointers */ MPII_Keyval_get_ptr( *win_keyval, keyval_ptr ); /* Validate parameters and objects (post conversion) */ # ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { MPII_Keyval_valid_ptr( keyval_ptr, mpi_errno ); if (mpi_errno) goto fn_fail; } MPID_END_ERROR_CHECKS; } # endif /* HAVE_ERROR_CHECKING */ /* ... body of routine ... */ if (!keyval_ptr->was_freed) { keyval_ptr->was_freed = 1; MPII_Keyval_release_ref( keyval_ptr, &in_use); if (!in_use) { MPIR_Handle_obj_free( &MPII_Keyval_mem, keyval_ptr ); } } *win_keyval = MPI_KEYVAL_INVALID; /* ... end of body of routine ... */ #ifdef HAVE_ERROR_CHECKING fn_exit: #endif MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_WIN_FREE_KEYVAL); MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); return mpi_errno; /* --BEGIN ERROR HANDLING-- */ # ifdef HAVE_ERROR_CHECKING fn_fail: { mpi_errno = MPIR_Err_create_code( mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_win_free_keyval", "**mpi_win_free_keyval %p", win_keyval); } mpi_errno = MPIR_Err_return_comm( NULL, FCNAME, mpi_errno ); goto fn_exit; # endif /* --END ERROR HANDLING-- */ }
/*@ MPI_Type_delete_attr - Deletes an attribute value associated with a key on a datatype Input Parameters: + datatype - MPI datatype to which attribute is attached (handle) - type_keyval - The key value of the deleted attribute (integer) .N ThreadSafe .N Fortran .N Errors .N MPI_SUCCESS .N MPI_ERR_OTHER .N MPI_ERR_KEYVAL @*/ int MPI_Type_delete_attr(MPI_Datatype datatype, int type_keyval) { static const char FCNAME[] = "MPI_Type_delete_attr"; int mpi_errno = MPI_SUCCESS; MPIR_Datatype *type_ptr = NULL; MPIR_Attribute *p, **old_p; MPII_Keyval *keyval_ptr = 0; MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_TYPE_DELETE_ATTR); MPIR_ERRTEST_INITIALIZED_ORDIE(); /* The thread lock prevents a valid attr delete on the same datatype but in a different thread from causing problems */ MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_TYPE_DELETE_ATTR); /* Validate parameters, especially handles needing to be converted */ # ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno); MPIR_ERRTEST_KEYVAL(type_keyval, MPIR_DATATYPE, "datatype", mpi_errno); MPIR_ERRTEST_KEYVAL_PERM(type_keyval, mpi_errno); } MPID_END_ERROR_CHECKS; } # endif /* Validate parameters and objects (post conversion) */ MPID_Datatype_get_ptr( datatype, type_ptr ); MPII_Keyval_get_ptr( type_keyval, keyval_ptr ); /* Validate parameters and objects (post conversion) */ # ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { /* Validate type_ptr */ MPIR_Datatype_valid_ptr( type_ptr, mpi_errno ); /* If type_ptr is not valid, it will be reset to null */ /* Validate keyval_ptr */ if (mpi_errno) goto fn_fail; } MPID_END_ERROR_CHECKS; } # endif /* HAVE_ERROR_CHECKING */ /* ... body of routine ... */ /* Look for attribute. They are ordered by keyval handle */ old_p = &type_ptr->attributes; p = type_ptr->attributes; while (p) { if (p->keyval->handle == keyval_ptr->handle) { break; } old_p = &p->next; p = p->next; } /* We can't unlock yet, because we must not free the attribute until we know whether the delete function has returned with a 0 status code */ if (p) { /* Run the delete function, if any, and then free the attribute storage */ mpi_errno = MPIR_Call_attr_delete( datatype, p ); /* --BEGIN ERROR HANDLING-- */ if (!mpi_errno) { int in_use; /* We found the attribute. Remove it from the list */ *old_p = p->next; /* Decrement the use of the keyval */ MPII_Keyval_release_ref( p->keyval, &in_use); if (!in_use) { MPIR_Handle_obj_free( &MPII_Keyval_mem, p->keyval ); } MPID_Attr_free(p); } /* --END ERROR HANDLING-- */ } if (mpi_errno != MPI_SUCCESS) goto fn_fail; /* ... end of body of routine ... */ fn_exit: MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_TYPE_DELETE_ATTR); MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); return mpi_errno; fn_fail: /* --BEGIN ERROR HANDLING-- */ # ifdef HAVE_ERROR_CHECKING { mpi_errno = MPIR_Err_create_code( mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_delete_attr", "**mpi_type_delete_attr %D %d", datatype, type_keyval); } # endif mpi_errno = MPIR_Err_return_comm( NULL, FCNAME, mpi_errno ); goto fn_exit; /* --END ERROR HANDLING-- */ }
int MPII_Type_set_attr(MPI_Datatype datatype, int type_keyval, void *attribute_val, MPIR_Attr_type attrType ) { static const char FCNAME[] = "MPII_Type_set_attr"; int mpi_errno = MPI_SUCCESS; MPIR_Datatype *type_ptr = NULL; MPII_Keyval *keyval_ptr = NULL; MPIR_Attribute *p, **old_p; MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPIR_TYPE_SET_ATTR); MPIR_ERRTEST_INITIALIZED_ORDIE(); /* The thread lock prevents a valid attr delete on the same datatype but in a different thread from causing problems */ MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPIR_TYPE_SET_ATTR); /* Validate parameters, especially handles needing to be converted */ # ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno); MPIR_ERRTEST_KEYVAL(type_keyval, MPIR_DATATYPE, "datatype", mpi_errno); MPIR_ERRTEST_KEYVAL_PERM(type_keyval, mpi_errno); } MPID_END_ERROR_CHECKS; } # endif /* Convert MPI object handles to object pointers */ MPID_Datatype_get_ptr( datatype, type_ptr ); MPII_Keyval_get_ptr( type_keyval, keyval_ptr ); /* Validate parameters and objects (post conversion) */ # ifdef HAVE_ERROR_CHECKING { MPID_BEGIN_ERROR_CHECKS; { /* Validate type_ptr */ MPIR_Datatype_valid_ptr( type_ptr, mpi_errno ); /* If type_ptr is not valid, it will be reset to null */ /* Validate keyval_ptr */ MPII_Keyval_valid_ptr( keyval_ptr, mpi_errno ); if (mpi_errno) goto fn_fail; } MPID_END_ERROR_CHECKS; } # endif /* HAVE_ERROR_CHECKING */ /* ... body of routine ... */ /* Look for attribute. They are ordered by keyval handle. This uses a simple linear list algorithm because few applications use more than a handful of attributes */ old_p = &type_ptr->attributes; p = type_ptr->attributes; while (p) { if (p->keyval->handle == keyval_ptr->handle) { /* If found, call the delete function before replacing the attribute */ mpi_errno = MPIR_Call_attr_delete( datatype, p ); /* --BEGIN ERROR HANDLING-- */ if (mpi_errno) { goto fn_fail; } /* --END ERROR HANDLING-- */ p->value = (MPII_Attr_val_t)(intptr_t)attribute_val; p->attrType = attrType; break; } else if (p->keyval->handle > keyval_ptr->handle) { MPIR_Attribute *new_p = MPID_Attr_alloc(); MPIR_ERR_CHKANDJUMP1(!new_p,mpi_errno,MPI_ERR_OTHER, "**nomem","**nomem %s", "MPIR_Attribute" ); new_p->keyval = keyval_ptr; new_p->attrType = attrType; new_p->pre_sentinal = 0; new_p->value = (MPII_Attr_val_t)(intptr_t)attribute_val; new_p->post_sentinal = 0; new_p->next = p->next; MPII_Keyval_add_ref( keyval_ptr ); p->next = new_p; break; } old_p = &p->next; p = p->next; } if (!p) { MPIR_Attribute *new_p = MPID_Attr_alloc(); MPIR_ERR_CHKANDJUMP1(!new_p,mpi_errno,MPI_ERR_OTHER, "**nomem","**nomem %s", "MPIR_Attribute" ); /* Did not find in list. Add at end */ new_p->keyval = keyval_ptr; new_p->attrType = attrType; new_p->pre_sentinal = 0; new_p->value = (MPII_Attr_val_t)(intptr_t)attribute_val; new_p->post_sentinal = 0; new_p->next = 0; MPII_Keyval_add_ref( keyval_ptr ); *old_p = new_p; } /* Here is where we could add a hook for the device to detect attribute value changes, using something like MPID_Type_attr_hook( type_ptr, keyval, attribute_val ); */ /* ... end of body of routine ... */ fn_exit: MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPIR_TYPE_SET_ATTR); MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX); return mpi_errno; fn_fail: /* --BEGIN ERROR HANDLING-- */ # ifdef HAVE_ERROR_CHECKING { mpi_errno = MPIR_Err_create_code( mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_set_attr", "**mpi_type_set_attr %D %d %p", datatype, type_keyval, attribute_val); } # endif mpi_errno = MPIR_Err_return_comm( NULL, FCNAME, mpi_errno ); goto fn_exit; /* --END ERROR HANDLING-- */ }