Callbacks signatures and behavior differ slightly from C, so try to do that correctly, if not cleanly
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)
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)
}
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<MPI_Win_copy_attr_function*>(copy_fn),
- reinterpret_cast<MPI_Win_delete_attr_function*>(delete_fn), keyval, extra_state);
+ smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_copy_attr_function_fort*>(copy_fn)};
+ smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_delete_attr_function_fort*>(delete_fn)};
+ *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
}
void mpi_win_free_keyval_(int* keyval, 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<MPI_Copy_function*>(copy_fn),reinterpret_cast<MPI_Delete_function*>(delete_fn), keyval, extra_state);
+ smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Copy_function_fort*>(copy_fn),nullptr,nullptr};
+ smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Delete_function_fort*>(delete_fn),nullptr,nullptr};
+ *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
}
void mpi_keyval_free_ (int* 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<MPI_Comm_copy_attr_function*>(copy_fn), reinterpret_cast<MPI_Comm_delete_attr_function*>(delete_fn),
- keyval, extra_state) ;
+ smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_copy_attr_function_fort*>(copy_fn),nullptr,nullptr};
+ smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_delete_attr_function_fort*>(delete_fn),nullptr,nullptr};
+ *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
}
void mpi_comm_free_keyval_ (int* 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<MPI_Type_copy_attr_function*>(copy_fn), reinterpret_cast<MPI_Type_delete_attr_function*>(delete_fn),
- keyval, extra_state) ;
+ smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Type_copy_attr_function_fort*>(copy_fn),nullptr};
+ smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Type_delete_attr_function_fort*>(delete_fn),nullptr};
+ *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state);
}
void mpi_type_free_keyval_ (int* keyval, int* ierr) {
}
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<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
}
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<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state);
}
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<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
}
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;
};
value->copy_fn=copy_fn;
value->delete_fn=delete_fn;
+ value->extra_state=extra_state;
value->refcount=1;
*keyval = T::keyval_id_;
elem->refcount++;
void * value = nullptr;
int flag=0;
- this->attr_get<T>(keyval, &value, &flag);
- if(flag!=0){
- int ret = call_deleter<T>((T*)this, elem, keyval,value,&flag);
+ auto p = attributes()->insert({keyval, attr_value});
+ if (!p.second) {
+ int ret = call_deleter<T>((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;
}
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});
}
*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});
}
}
}
template <> int Keyval::call_deleter<Comm>(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>(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>(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;
}
}