From: Augustin Degomme Date: Tue, 25 Sep 2018 09:29:09 +0000 (+0200) Subject: Have attributes actually work in fortran... the horror X-Git-Tag: v3_21~40 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ede4cf5925f79bf5544eb880574789c28e086d8e?ds=sidebyside Have attributes actually work in fortran... the horror Callbacks signatures and behavior differ slightly from C, so try to do that correctly, if not cleanly --- diff --git a/include/smpi/mpif.h.in b/include/smpi/mpif.h.in index 2a435903ad..1f01d370e2 100644 --- a/include/smpi/mpif.h.in +++ b/include/smpi/mpif.h.in @@ -79,14 +79,18 @@ integer MPI_COMM_NULL_COPY_FN, MPI_COMM_NULL_DELETE_FN parameter(MPI_COMM_NULL_COPY_FN =0) parameter(MPI_COMM_NULL_DELETE_FN =0) - integer MPI_COMM_NULL_DUP_FN, MPI_COMM_DUP_FN - parameter(MPI_COMM_NULL_DUP_FN =0) - parameter(MPI_COMM_DUP_FN =0) + integer MPI_COMM_DUP_FN + parameter(MPI_COMM_DUP_FN =1) integer MPI_WIN_NULL_COPY_FN, MPI_WIN_NULL_DELETE_FN parameter(MPI_WIN_NULL_COPY_FN =0) parameter(MPI_WIN_NULL_DELETE_FN =0) integer MPI_WIN_DUP_FN - parameter(MPI_WIN_DUP_FN =0) + parameter(MPI_WIN_DUP_FN =1) + integer MPI_TYPE_NULL_COPY_FN, MPI_TYPE_NULL_DELETE_FN + parameter(MPI_TYPE_NULL_COPY_FN =0) + parameter(MPI_TYPE_NULL_DELETE_FN =0) + integer MPI_TYPE_DUP_FN + parameter(MPI_TYPE_DUP_FN =1) integer MPI_ROOT, MPI_COMM_TYPE_SHARED parameter(MPI_ROOT=0) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 51f09396db..9af55d8956 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -372,14 +372,25 @@ typedef enum SMPI_Topo_type { typedef int MPI_Copy_function(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in, void* attribute_val_out, int* flag); typedef int MPI_Delete_function(MPI_Comm comm, int keyval, void* attribute_val, void* extra_state); +typedef void MPI_Copy_function_fort(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in, + void* attribute_val_out, int* flag, int* ierr); +typedef void MPI_Delete_function_fort(MPI_Comm comm, int keyval, void* attribute_val, void* extra_state, int* ierr); #define MPI_Comm_copy_attr_function MPI_Copy_function #define MPI_Comm_delete_attr_function MPI_Delete_function +#define MPI_Comm_copy_attr_function_fort MPI_Copy_function_fort +#define MPI_Comm_delete_attr_function_fort MPI_Delete_function_fort typedef int MPI_Type_copy_attr_function(MPI_Datatype type, int keyval, void* extra_state, void* attribute_val_in, void* attribute_val_out, int* flag); typedef int MPI_Type_delete_attr_function(MPI_Datatype type, int keyval, void* attribute_val, void* extra_state); typedef int MPI_Win_copy_attr_function(MPI_Win win, int keyval, void* extra_state, void* attribute_val_in, void* attribute_val_out, int* flag); typedef int MPI_Win_delete_attr_function(MPI_Win win, int keyval, void* attribute_val, void* extra_state); +typedef void MPI_Type_copy_attr_function_fort(MPI_Datatype type, int keyval, void* extra_state, void* attribute_val_in, + void* attribute_val_out, int* flag, int* ierr); +typedef void MPI_Type_delete_attr_function_fort(MPI_Datatype type, int keyval, void* attribute_val, void* extra_state, int* ierr); +typedef void MPI_Win_copy_attr_function_fort(MPI_Win win, int keyval, void* extra_state, void* attribute_val_in, + void* attribute_val_out, int* flag, int* ierr); +typedef void MPI_Win_delete_attr_function_fort(MPI_Win win, int keyval, void* attribute_val, void* extra_state, int* ierr); #define MPI_COMM_NULL_COPY_FN ((MPI_Comm_copy_attr_function*)0) #define MPI_COMM_NULL_DELETE_FN ((MPI_Comm_delete_attr_function*)0) #define MPI_TYPE_NULL_COPY_FN ((MPI_Type_copy_attr_function*)0) diff --git a/src/smpi/bindings/smpi_f77.cpp b/src/smpi/bindings/smpi_f77.cpp index f28922c280..42165e3b98 100644 --- a/src/smpi/bindings/smpi_f77.cpp +++ b/src/smpi/bindings/smpi_f77.cpp @@ -244,8 +244,9 @@ void mpi_win_delete_attr_(int* win, int* comm_keyval, int* ierr){ } void mpi_win_create_keyval_(void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){ - *ierr = MPI_Win_create_keyval(reinterpret_cast(copy_fn), - reinterpret_cast(delete_fn), keyval, extra_state); + smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast(copy_fn)}; + smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast(delete_fn)}; + *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } void mpi_win_free_keyval_(int* keyval, int* ierr){ @@ -718,7 +719,9 @@ void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) { } void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) { - *ierr = MPI_Keyval_create(reinterpret_cast(copy_fn),reinterpret_cast(delete_fn), keyval, extra_state); + smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast(copy_fn),nullptr,nullptr}; + smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast(delete_fn),nullptr,nullptr}; + *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } void mpi_keyval_free_ (int* keyval, int* ierr) { diff --git a/src/smpi/bindings/smpi_f77_comm.cpp b/src/smpi/bindings/smpi_f77_comm.cpp index 02893b993e..3e051e5207 100644 --- a/src/smpi/bindings/smpi_f77_comm.cpp +++ b/src/smpi/bindings/smpi_f77_comm.cpp @@ -90,9 +90,9 @@ void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){ } void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){ - - *ierr = MPI_Comm_create_keyval(reinterpret_cast(copy_fn), reinterpret_cast(delete_fn), - keyval, extra_state) ; + smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast(copy_fn),nullptr,nullptr}; + smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast(delete_fn),nullptr,nullptr}; + *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } void mpi_comm_free_keyval_ (int* keyval, int* ierr) { diff --git a/src/smpi/bindings/smpi_f77_type.cpp b/src/smpi/bindings/smpi_f77_type.cpp index 94773b8f33..ffd647b1c7 100644 --- a/src/smpi/bindings/smpi_f77_type.cpp +++ b/src/smpi/bindings/smpi_f77_type.cpp @@ -75,9 +75,9 @@ void mpi_type_delete_attr_ (int* type, int* type_keyval, int* ierr){ } void mpi_type_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){ - - *ierr = MPI_Type_create_keyval(reinterpret_cast(copy_fn), reinterpret_cast(delete_fn), - keyval, extra_state) ; + smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast(copy_fn),nullptr}; + smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast(delete_fn),nullptr}; + *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } void mpi_type_free_keyval_ (int* keyval, int* ierr) { diff --git a/src/smpi/bindings/smpi_pmpi.cpp b/src/smpi/bindings/smpi_pmpi.cpp index e8622ac0cf..08daa6639b 100644 --- a/src/smpi/bindings/smpi_pmpi.cpp +++ b/src/smpi/bindings/smpi_pmpi.cpp @@ -223,8 +223,8 @@ int PMPI_Error_string(int errorcode, char* string, int* resultlen){ } int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) { - smpi_copy_fn _copy_fn={copy_fn,nullptr,nullptr}; - smpi_delete_fn _delete_fn={delete_fn,nullptr,nullptr}; + smpi_copy_fn _copy_fn={copy_fn,nullptr,nullptr,nullptr,nullptr,nullptr}; + smpi_delete_fn _delete_fn={delete_fn,nullptr,nullptr,nullptr,nullptr,nullptr}; return simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } diff --git a/src/smpi/bindings/smpi_pmpi_type.cpp b/src/smpi/bindings/smpi_pmpi_type.cpp index ada61b8da9..5fcc10636a 100644 --- a/src/smpi/bindings/smpi_pmpi_type.cpp +++ b/src/smpi/bindings/smpi_pmpi_type.cpp @@ -325,8 +325,8 @@ int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval) int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state) { - smpi_copy_fn _copy_fn={nullptr,copy_fn,nullptr}; - smpi_delete_fn _delete_fn={nullptr,delete_fn,nullptr}; + smpi_copy_fn _copy_fn={nullptr,copy_fn,nullptr,nullptr,nullptr,nullptr}; + smpi_delete_fn _delete_fn={nullptr,delete_fn,nullptr,nullptr,nullptr,nullptr}; return simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } diff --git a/src/smpi/bindings/smpi_pmpi_win.cpp b/src/smpi/bindings/smpi_pmpi_win.cpp index 5a8ca346b2..b3ca2d7134 100644 --- a/src/smpi/bindings/smpi_pmpi_win.cpp +++ b/src/smpi/bindings/smpi_pmpi_win.cpp @@ -829,8 +829,8 @@ int PMPI_Win_delete_attr (MPI_Win win, int type_keyval) int PMPI_Win_create_keyval(MPI_Win_copy_attr_function* copy_fn, MPI_Win_delete_attr_function* delete_fn, int* keyval, void* extra_state) { - smpi_copy_fn _copy_fn={nullptr, nullptr, copy_fn}; - smpi_delete_fn _delete_fn={nullptr, nullptr, delete_fn}; + smpi_copy_fn _copy_fn={nullptr, nullptr,copy_fn,nullptr, nullptr,nullptr}; + smpi_delete_fn _delete_fn={nullptr, nullptr,delete_fn,nullptr, nullptr,nullptr}; return simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); } diff --git a/src/smpi/include/smpi_keyvals.hpp b/src/smpi/include/smpi_keyvals.hpp index 1f8ce73a29..43daa90d20 100644 --- a/src/smpi/include/smpi_keyvals.hpp +++ b/src/smpi/include/smpi_keyvals.hpp @@ -14,17 +14,24 @@ struct smpi_delete_fn { MPI_Comm_delete_attr_function *comm_delete_fn; MPI_Type_delete_attr_function *type_delete_fn; MPI_Win_delete_attr_function *win_delete_fn; + MPI_Comm_delete_attr_function_fort *comm_delete_fn_fort; + MPI_Type_delete_attr_function_fort *type_delete_fn_fort; + MPI_Win_delete_attr_function_fort *win_delete_fn_fort; }; struct smpi_copy_fn { MPI_Comm_copy_attr_function *comm_copy_fn; MPI_Type_copy_attr_function *type_copy_fn; MPI_Win_copy_attr_function *win_copy_fn; + MPI_Comm_copy_attr_function_fort *comm_copy_fn_fort; + MPI_Type_copy_attr_function_fort *type_copy_fn_fort; + MPI_Win_copy_attr_function_fort *win_copy_fn_fort; }; struct s_smpi_key_elem_t { smpi_copy_fn copy_fn; smpi_delete_fn delete_fn; + void* extra_state; int refcount; }; @@ -57,6 +64,7 @@ template int Keyval::keyval_create(smpi_copy_fn copy_fn, smpi_delet value->copy_fn=copy_fn; value->delete_fn=delete_fn; + value->extra_state=extra_state; value->refcount=1; *keyval = T::keyval_id_; @@ -126,13 +134,14 @@ template int Keyval::attr_put(int keyval, void* attr_value){ elem->refcount++; void * value = nullptr; int flag=0; - this->attr_get(keyval, &value, &flag); - if(flag!=0){ - int ret = call_deleter((T*)this, elem, keyval,value,&flag); + auto p = attributes()->insert({keyval, attr_value}); + if (!p.second) { + int ret = call_deleter((T*)this, elem, keyval,p.first->second,&flag); + // overwrite previous value + p.first->second = attr_value; if(ret!=MPI_SUCCESS) - return ret; + return ret; } - attributes()->insert({keyval, attr_value}); return MPI_SUCCESS; } diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 57c61d292b..47cf004ada 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -61,18 +61,29 @@ int Comm::dup(MPI_Comm* newcomm){ int ret = MPI_SUCCESS; if (not attributes()->empty()) { - int flag; - void* value_out; + int flag=0; + void* value_out=nullptr; for (auto const& it : *attributes()) { smpi_key_elem elem = keyvals_.at(it.first); - if (elem != nullptr && elem->copy_fn.comm_copy_fn != MPI_NULL_COPY_FN) { - ret = elem->copy_fn.comm_copy_fn(this, it.first, nullptr, it.second, &value_out, &flag); + if (elem != nullptr){ + if( elem->copy_fn.comm_copy_fn != MPI_NULL_COPY_FN && + elem->copy_fn.comm_copy_fn != MPI_COMM_DUP_FN) + ret = elem->copy_fn.comm_copy_fn(this, it.first, elem->extra_state, it.second, &value_out, &flag); + else if ( elem->copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN && + *(int*)*elem->copy_fn.comm_copy_fn_fort != 1){ + value_out=(int*)xbt_malloc(sizeof(int)); + elem->copy_fn.comm_copy_fn_fort(this, it.first, elem->extra_state, it.second, value_out, &flag,&ret); + } if (ret != MPI_SUCCESS) { Comm::destroy(*newcomm); *newcomm = MPI_COMM_NULL; return ret; } - if (flag){ + if (elem->copy_fn.comm_copy_fn == MPI_COMM_DUP_FN || + ((elem->copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) && *(int*)*elem->copy_fn.comm_copy_fn_fort == 1)){ + elem->refcount++; + (*newcomm)->attributes()->insert({it.first, it.second}); + }else if (flag){ elem->refcount++; (*newcomm)->attributes()->insert({it.first, value_out}); } diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index 5136911deb..c9b75ab4ac 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -128,21 +128,31 @@ Datatype::Datatype(Datatype *datatype, int* ret) : name_(nullptr), lb_(datatype- *ret = MPI_SUCCESS; if(datatype->name_) name_ = xbt_strdup(datatype->name_); - + if (not datatype->attributes()->empty()) { - int flag; + int flag=0; void* value_out; - for(auto it = datatype->attributes()->begin(); it != datatype->attributes()->end(); it++){ - smpi_key_elem elem = keyvals_.at((*it).first); - - if (elem != nullptr && elem->copy_fn.type_copy_fn != MPI_NULL_COPY_FN) { - *ret = elem->copy_fn.type_copy_fn(datatype, (*it).first, nullptr, (*it).second, &value_out, &flag); + for (auto const& it : *(datatype->attributes())) { + smpi_key_elem elem = keyvals_.at(it.first); + if (elem != nullptr){ + if( elem->copy_fn.type_copy_fn != MPI_NULL_COPY_FN && + elem->copy_fn.type_copy_fn != MPI_TYPE_DUP_FN) + *ret = elem->copy_fn.type_copy_fn(datatype, it.first, elem->extra_state, it.second, &value_out, &flag); + else if ( elem->copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN && + (*(int*)*elem->copy_fn.type_copy_fn_fort) != 1){ + value_out=(int*)xbt_malloc(sizeof(int)); + elem->copy_fn.type_copy_fn_fort(datatype, it.first, elem->extra_state, it.second, value_out, &flag,ret); + } if (*ret != MPI_SUCCESS) { break; } - if (flag){ + if(elem->copy_fn.type_copy_fn == MPI_TYPE_DUP_FN || + ((elem->copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) && (*(int*)*elem->copy_fn.type_copy_fn_fort == 1))){ + elem->refcount++; + attributes()->insert({it.first, it.second}); + } else if (flag){ elem->refcount++; - attributes()->insert({(*it).first, value_out}); + attributes()->insert({it.first, value_out}); } } } diff --git a/src/smpi/mpi/smpi_keyvals.cpp b/src/smpi/mpi/smpi_keyvals.cpp index 47728de2b9..35b82ffd11 100644 --- a/src/smpi/mpi/smpi_keyvals.cpp +++ b/src/smpi/mpi/smpi_keyvals.cpp @@ -16,30 +16,30 @@ std::unordered_map* Keyval::attributes(){ template <> int Keyval::call_deleter(Comm* obj, smpi_key_elem elem, int keyval, void * value, int* flag){ - if(elem->delete_fn.comm_delete_fn!=MPI_NULL_DELETE_FN){ - int ret = elem->delete_fn.comm_delete_fn(obj, keyval, value, flag); - if(ret!=MPI_SUCCESS) - return ret; - } - return MPI_SUCCESS; + int ret = MPI_SUCCESS; + if(elem->delete_fn.comm_delete_fn!=MPI_NULL_DELETE_FN) + ret = elem->delete_fn.comm_delete_fn(obj, keyval, value, elem->extra_state); + else if(elem->delete_fn.comm_delete_fn_fort!=MPI_NULL_DELETE_FN) + elem->delete_fn.comm_delete_fn_fort(obj, keyval, value, elem->extra_state, &ret); + return ret; } template <> int Keyval::call_deleter(Win* obj, smpi_key_elem elem, int keyval, void * value, int* flag){ - if(elem->delete_fn.win_delete_fn!=MPI_NULL_DELETE_FN){ - int ret = elem->delete_fn.win_delete_fn(obj, keyval, value, flag); - if(ret!=MPI_SUCCESS) - return ret; - } - return MPI_SUCCESS; + int ret = MPI_SUCCESS; + if(elem->delete_fn.win_delete_fn!=MPI_NULL_DELETE_FN) + ret = elem->delete_fn.win_delete_fn(obj, keyval, value, elem->extra_state); + else if(elem->delete_fn.win_delete_fn_fort!=MPI_NULL_DELETE_FN) + elem->delete_fn.win_delete_fn_fort(obj, keyval, value, elem->extra_state, &ret); + return ret; } template <> int Keyval::call_deleter(Datatype* obj, smpi_key_elem elem, int keyval, void * value, int* flag){ - if(elem->delete_fn.type_delete_fn!=MPI_NULL_DELETE_FN){ - int ret = elem->delete_fn.type_delete_fn(obj, keyval, value, flag); - if(ret!=MPI_SUCCESS) - return ret; - } - return MPI_SUCCESS; + int ret = MPI_SUCCESS; + if(elem->delete_fn.type_delete_fn!=MPI_NULL_DELETE_FN) + ret = elem->delete_fn.type_delete_fn(obj, keyval, value, elem->extra_state); + else if(elem->delete_fn.type_delete_fn_fort!=MPI_NULL_DELETE_FN) + elem->delete_fn.type_delete_fn_fort(obj, keyval, value, elem->extra_state, &ret); + return ret; } }