diff --git a/ompi/attribute/attribute.c b/ompi/attribute/attribute.c index bbdc5aed0a..7463f0dc42 100644 --- a/ompi/attribute/attribute.c +++ b/ompi/attribute/attribute.c @@ -251,7 +251,7 @@ MPI_Fint attr_val = translate_to_fortran_mpi1(attribute); \ (*((keyval_obj->delete_attr_fn).attr_mpi1_fortran_delete_fn)) \ (&(((ompi_##type##_t *)object)->attr_##type##_f), \ - &f_key, &attr_val, (int*)keyval_obj->extra_state, &f_err); \ + &f_key, &attr_val, &keyval_obj->extra_state.f_integer, &f_err); \ if (MPI_SUCCESS != OMPI_FINT_2_INT(f_err)) { \ if (need_lock) { \ OPAL_THREAD_UNLOCK(&alock); \ @@ -264,7 +264,7 @@ MPI_Aint attr_val = translate_to_fortran_mpi2(attribute); \ (*((keyval_obj->delete_attr_fn).attr_mpi2_fortran_delete_fn)) \ (&(((ompi_##type##_t *)object)->attr_##type##_f), \ - &f_key, (int*)&attr_val, (int*)keyval_obj->extra_state, &f_err); \ + &f_key, (int*)&attr_val, &keyval_obj->extra_state.f_address, &f_err); \ if (MPI_SUCCESS != OMPI_FINT_2_INT(f_err)) { \ if (need_lock) { \ OPAL_THREAD_UNLOCK(&alock); \ @@ -279,7 +279,7 @@ if ((err = (*((keyval_obj->delete_attr_fn).attr_##type##_delete_fn)) \ ((ompi_##type##_t *)object, \ key, attr_val, \ - keyval_obj->extra_state)) != MPI_SUCCESS) {\ + keyval_obj->extra_state.c_ptr)) != MPI_SUCCESS) {\ if (need_lock) { \ OPAL_THREAD_UNLOCK(&alock); \ } \ @@ -297,11 +297,11 @@ ompi_fortran_logical_t f_flag; \ /* MPI-1 Fortran-style */ \ if (0 != (keyval_obj->attr_flag & OMPI_KEYVAL_F77_MPI1)) { \ - MPI_Fint in, out; \ + MPI_Fint in, out; \ in = translate_to_fortran_mpi1(in_attr); \ (*((keyval_obj->copy_attr_fn).attr_mpi1_fortran_copy_fn)) \ (&(((ompi_##type##_t *)old_object)->attr_##type##_f), \ - &f_key, (int*)keyval_obj->extra_state, \ + &f_key, &keyval_obj->extra_state.f_integer, \ &in, &out, &f_flag, &f_err); \ if (MPI_SUCCESS != OMPI_FINT_2_INT(f_err)) { \ OPAL_THREAD_UNLOCK(&alock); \ @@ -313,11 +313,11 @@ } \ /* MPI-2 Fortran-style */ \ else { \ - MPI_Aint in, out; \ + MPI_Aint in, out; \ in = translate_to_fortran_mpi2(in_attr); \ (*((keyval_obj->copy_attr_fn).attr_mpi2_fortran_copy_fn)) \ (&(((ompi_##type##_t *)old_object)->attr_##type##_f), \ - &f_key, keyval_obj->extra_state, &in, &out, \ + &f_key, &keyval_obj->extra_state.f_address, &in, &out, \ &f_flag, &f_err); \ if (MPI_SUCCESS != OMPI_FINT_2_INT(f_err)) { \ OPAL_THREAD_UNLOCK(&alock); \ @@ -332,7 +332,7 @@ void *in, *out; \ in = translate_to_c(in_attr); \ if ((err = (*((keyval_obj->copy_attr_fn).attr_##type##_copy_fn)) \ - ((ompi_##type##_t *)old_object, key, keyval_obj->extra_state, \ + ((ompi_##type##_t *)old_object, key, keyval_obj->extra_state.c_ptr, \ in, &out, &flag, (ompi_##type##_t *)(new_object))) != MPI_SUCCESS) { \ OPAL_THREAD_UNLOCK(&alock); \ return err; \ @@ -438,7 +438,7 @@ ompi_attribute_keyval_construct(ompi_attribute_keyval_t *keyval) keyval->attr_flag = 0; keyval->copy_attr_fn.attr_communicator_copy_fn = NULL; keyval->delete_attr_fn.attr_communicator_copy_fn = NULL; - keyval->extra_state = NULL; + keyval->extra_state.c_ptr = NULL; keyval->bindings_extra_state = NULL; /* Set the keyval->key value to an invalid value so that we can know @@ -530,10 +530,12 @@ int ompi_attr_finalize(void) } -int ompi_attr_create_keyval(ompi_attribute_type_t type, +static int ompi_attr_create_keyval_impl(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, + int *key, + ompi_attribute_fortran_ptr_t *extra_state, + int flags, void *bindings_extra_state) { ompi_attribute_keyval_t *keyval; @@ -558,7 +560,7 @@ int ompi_attr_create_keyval(ompi_attribute_type_t type, keyval->copy_attr_fn = copy_attr_fn; keyval->delete_attr_fn = delete_attr_fn; - keyval->extra_state = extra_state; + keyval->extra_state = *extra_state; keyval->attr_type = type; keyval->attr_flag = flags; keyval->key = -1; @@ -582,6 +584,53 @@ int ompi_attr_create_keyval(ompi_attribute_type_t type, return MPI_SUCCESS; } +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) +{ + ompi_attribute_fortran_ptr_t es_tmp; + + es_tmp.c_ptr = extra_state; + return ompi_attr_create_keyval_impl(type, copy_attr_fn, delete_attr_fn, + key, &es_tmp, flags, + bindings_extra_state); +} + +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) +{ + ompi_attribute_fortran_ptr_t es_tmp; + + es_tmp.f_integer = extra_state; + return ompi_attr_create_keyval_impl(type, copy_attr_fn, delete_attr_fn, + key, &es_tmp, flags, + bindings_extra_state); +} + +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) +{ + ompi_attribute_fortran_ptr_t es_tmp; + + es_tmp.f_address = extra_state; + return ompi_attr_create_keyval_impl(type, copy_attr_fn, delete_attr_fn, + key, &es_tmp, flags, + bindings_extra_state); +} int ompi_attr_free_keyval(ompi_attribute_type_t type, int *key, bool predefined) diff --git a/ompi/attribute/attribute.h b/ompi/attribute/attribute.h index 6926ccdd54..3ded2fa307 100644 --- a/ompi/attribute/attribute.h +++ b/ompi/attribute/attribute.h @@ -144,6 +144,7 @@ typedef union ompi_attribute_fn_ptr_union_t ompi_attribute_fn_ptr_union_t; union ompi_attribute_fortran_ptr_t { void *c_ptr; MPI_Fint f_integer; + MPI_Aint f_address; }; /** * Convenience typedef @@ -162,7 +163,7 @@ struct ompi_attribute_keyval_t { attribute */ ompi_attribute_fn_ptr_union_t delete_attr_fn; /**< Delete function for the attribute */ - void *extra_state; /**< Extra state of 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 */ @@ -252,6 +253,26 @@ OMPI_DECLSPEC int ompi_attr_create_keyval(ompi_attribute_type_t type, 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) diff --git a/ompi/mpi/f77/comm_create_keyval_f.c b/ompi/mpi/f77/comm_create_keyval_f.c index d4863f0e40..d2dc380d31 100644 --- a/ompi/mpi/f77/comm_create_keyval_f.c +++ b/ompi/mpi/f77/comm_create_keyval_f.c @@ -62,9 +62,9 @@ OMPI_GENERATE_F77_BINDINGS (MPI_COMM_CREATE_KEYVAL, static const char FUNC_NAME[] = "MPI_Comm_create_keyval_f"; void mpi_comm_create_keyval_f(ompi_mpi2_fortran_copy_attr_function* comm_copy_attr_fn, - ompi_mpi2_fortran_delete_attr_function* comm_delete_attr_fn, - MPI_Fint *comm_keyval, - MPI_Aint *extra_state, MPI_Fint *ierr) + ompi_mpi2_fortran_delete_attr_function* comm_delete_attr_fn, + MPI_Fint *comm_keyval, + MPI_Aint *extra_state, MPI_Fint *ierr) { int ret, c_err; ompi_attribute_fn_ptr_union_t copy_fn; @@ -78,15 +78,15 @@ void mpi_comm_create_keyval_f(ompi_mpi2_fortran_copy_attr_function* comm_copy_at INTEGER(KIND=MPI_ADDRESS_KIND)-parameter functions (as opposed to the old MPI-1 INTEGER-parameter functions). */ - ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn, del_fn, - comm_keyval, extra_state, OMPI_KEYVAL_F77, - NULL); + ret = ompi_attr_create_keyval_aint(COMM_ATTR, copy_fn, del_fn, + comm_keyval, *extra_state, OMPI_KEYVAL_F77, + NULL); if (MPI_SUCCESS != ret) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, - MPI_ERR_OTHER, - FUNC_NAME) - *ierr = OMPI_INT_2_FINT(c_err); + MPI_ERR_OTHER, + FUNC_NAME) + *ierr = OMPI_INT_2_FINT(c_err); } else { *ierr = OMPI_INT_2_FINT(MPI_SUCCESS); } diff --git a/ompi/mpi/f77/keyval_create_f.c b/ompi/mpi/f77/keyval_create_f.c index 175e45ed89..28c34f0761 100644 --- a/ompi/mpi/f77/keyval_create_f.c +++ b/ompi/mpi/f77/keyval_create_f.c @@ -63,7 +63,7 @@ static const char FUNC_NAME[] = "MPI_keyval_create_f"; void mpi_keyval_create_f(ompi_mpi1_fortran_copy_attr_function* copy_attr_fn, ompi_mpi1_fortran_delete_attr_function* delete_attr_fn, - MPI_Fint *keyval, MPI_Fint *extra_state, + MPI_Fint *keyval, MPI_Fint *extra_state, MPI_Fint *ierr) { int ret, c_err; @@ -78,16 +78,16 @@ void mpi_keyval_create_f(ompi_mpi1_fortran_copy_attr_function* copy_attr_fn, new MPI-2 INTEGER(KIND=MPI_ADDRESS_KIND)-parameter functions). */ - ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn, del_fn, - keyval, extra_state, - OMPI_KEYVAL_F77 | OMPI_KEYVAL_F77_MPI1, - NULL); + ret = ompi_attr_create_keyval_fint(COMM_ATTR, copy_fn, del_fn, + keyval, *extra_state, + OMPI_KEYVAL_F77 | OMPI_KEYVAL_F77_MPI1, + NULL); if (MPI_SUCCESS != ret) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, - MPI_ERR_OTHER, - FUNC_NAME); - *ierr = OMPI_INT_2_FINT(c_err); + MPI_ERR_OTHER, + FUNC_NAME); + *ierr = OMPI_INT_2_FINT(c_err); } else { *ierr = OMPI_INT_2_FINT(MPI_SUCCESS); } diff --git a/ompi/mpi/f77/type_create_keyval_f.c b/ompi/mpi/f77/type_create_keyval_f.c index b86a8c557e..ba684d6005 100644 --- a/ompi/mpi/f77/type_create_keyval_f.c +++ b/ompi/mpi/f77/type_create_keyval_f.c @@ -75,15 +75,15 @@ void mpi_type_create_keyval_f(ompi_mpi2_fortran_copy_attr_function* type_copy_at INTEGER(KIND=MPI_ADDRESS_KIND)-parameter functions (as opposed to the old MPI-1 INTEGER-parameter functions). */ - ret = ompi_attr_create_keyval(TYPE_ATTR, copy_fn, del_fn, - type_keyval, extra_state, OMPI_KEYVAL_F77, - NULL); + ret = ompi_attr_create_keyval_aint(TYPE_ATTR, copy_fn, del_fn, + type_keyval, *extra_state, OMPI_KEYVAL_F77, + NULL); if (MPI_SUCCESS != ret) { - c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, - MPI_ERR_OTHER, - FUNC_NAME); - *ierr = OMPI_INT_2_FINT(c_err); + c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, + MPI_ERR_OTHER, + FUNC_NAME); + *ierr = OMPI_INT_2_FINT(c_err); } else { *ierr = OMPI_INT_2_FINT(MPI_SUCCESS); } diff --git a/ompi/mpi/f77/win_create_keyval_f.c b/ompi/mpi/f77/win_create_keyval_f.c index 54003a5e20..3256a4a70a 100644 --- a/ompi/mpi/f77/win_create_keyval_f.c +++ b/ompi/mpi/f77/win_create_keyval_f.c @@ -77,14 +77,14 @@ void mpi_win_create_keyval_f(ompi_mpi2_fortran_copy_attr_function* win_copy_attr INTEGER(KIND=MPI_ADDRESS_KIND)-parameter functions (as opposed to the old MPI-1 INTEGER-parameter functions). */ - ret = ompi_attr_create_keyval(WIN_ATTR, copy_fn, del_fn, - win_keyval, extra_state, OMPI_KEYVAL_F77, - NULL); + ret = ompi_attr_create_keyval_aint(WIN_ATTR, copy_fn, del_fn, + win_keyval, *extra_state, OMPI_KEYVAL_F77, + NULL); if (MPI_SUCCESS != ret) { c_err = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER, - FUNC_NAME); - *ierr = OMPI_INT_2_FINT(c_err); + FUNC_NAME); + *ierr = OMPI_INT_2_FINT(c_err); } else { *ierr = OMPI_INT_2_FINT(MPI_SUCCESS); }