X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1555ef43eee251e5892a2f7fd49bc96e99d68fef..0eead244337fde8f0508629f8f8473f946c19f88:/src/smpi/smpi_mpi_dt.cpp diff --git a/src/smpi/smpi_mpi_dt.cpp b/src/smpi/smpi_mpi_dt.cpp index 43af712336..e948b65137 100644 --- a/src/smpi/smpi_mpi_dt.cpp +++ b/src/smpi/smpi_mpi_dt.cpp @@ -25,12 +25,12 @@ int type_keyval_id=0;//avoid collisions static s_smpi_mpi_datatype_t mpi_##name = { \ (char*) # name, \ sizeof(type), /* size */ \ - 0, /*was 1 sizeof_substruct*/ \ + 0, /*was 1 sizeof_substruct*/ \ 0, /* lb */ \ sizeof(type), /* ub = lb + size */ \ DT_FLAG_BASIC, /* flags */ \ - nullptr, /* attributes */ \ - nullptr, /* pointer on extended struct*/ \ + nullptr, /* attributes */ \ + nullptr, /* pointer on extended struct*/ \ 0 /* in_use counter */ \ }; \ const MPI_Datatype name = &mpi_##name; @@ -39,12 +39,12 @@ const MPI_Datatype name = &mpi_##name; static s_smpi_mpi_datatype_t mpi_##name = { \ (char*) # name, \ 0, /* size */ \ - 0, /* was 1 sizeof_substruct*/ \ + 0, /* was 1 sizeof_substruct*/ \ 0, /* lb */ \ 0, /* ub = lb + size */ \ DT_FLAG_BASIC, /* flags */ \ - nullptr, /* attributes */ \ - nullptr, /* pointer on extended struct*/ \ + nullptr, /* attributes */ \ + nullptr, /* pointer on extended struct*/ \ 0 /* in_use counter */ \ }; \ const MPI_Datatype name = &mpi_##name; @@ -186,26 +186,26 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t) if(datatype->name) (*new_t)->name = xbt_strdup(datatype->name); if(datatype->attributes !=nullptr){ - (*new_t)->attributes=xbt_dict_new(); - xbt_dict_cursor_t cursor = nullptr; - int *key; - int flag; - void* value_in; - void* value_out; - xbt_dict_foreach(datatype->attributes, cursor, key, value_in){ - smpi_type_key_elem elem = - static_cast(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast(key), sizeof(int))); - if(elem != nullptr && elem->copy_fn!=MPI_NULL_COPY_FN){ - ret = elem->copy_fn(datatype, *key, nullptr, value_in, &value_out, &flag ); - if(ret!=MPI_SUCCESS){ - smpi_datatype_unuse(*new_t); - *new_t=MPI_DATATYPE_NULL; - xbt_dict_cursor_free(&cursor); - return ret; - } - if(flag) - xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast(key), sizeof(int),value_out, nullptr); + (*new_t)->attributes = xbt_dict_new_homogeneous(nullptr); + xbt_dict_cursor_t cursor = nullptr; + int* key; + int flag; + void* value_in; + void* value_out; + xbt_dict_foreach (datatype->attributes, cursor, key, value_in) { + smpi_type_key_elem elem = static_cast( + xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast(key), sizeof(int))); + if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) { + ret = elem->copy_fn(datatype, *key, nullptr, value_in, &value_out, &flag); + if (ret != MPI_SUCCESS) { + smpi_datatype_unuse(*new_t); + *new_t = MPI_DATATYPE_NULL; + xbt_dict_cursor_free(&cursor); + return ret; } + if (flag) + xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast(key), sizeof(int), value_out, nullptr); + } } } return ret; @@ -436,7 +436,11 @@ void smpi_datatype_use(MPI_Datatype type){ #endif } -void smpi_datatype_unuse(MPI_Datatype type){ +void smpi_datatype_unuse(MPI_Datatype type) +{ + if (type == MPI_DATATYPE_NULL) + return; + if (type->in_use > 0) type->in_use--; @@ -444,9 +448,9 @@ void smpi_datatype_unuse(MPI_Datatype type){ static_cast((type)->substruct)->subtype_free(&type); } - if(type != MPI_DATATYPE_NULL && type->in_use == 0){ + if (type->in_use == 0) smpi_datatype_free(&type); - } + #if HAVE_MC if(MC_is_active()) MC_ignore(&(type->in_use), sizeof(type->in_use)); @@ -930,8 +934,7 @@ s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths, MPI_Ai new_t->base.subtype_use = &use_hindexed; new_t->block_lengths= xbt_new(int, block_count); new_t->block_indices= xbt_new(MPI_Aint, block_count); - int i; - for(i=0;iblock_lengths[i]=block_lengths[i]; new_t->block_indices[i]=block_indices[i]; } @@ -1607,7 +1610,7 @@ int smpi_type_attr_get(MPI_Datatype type, int keyval, void* attr_value, int* fla int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){ if(smpi_type_keyvals==nullptr) - smpi_type_keyvals = xbt_dict_new(); + smpi_type_keyvals = xbt_dict_new_homogeneous(nullptr); smpi_type_key_elem elem = static_cast(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast(&keyval), sizeof(int))); if(elem==nullptr) @@ -1621,7 +1624,7 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){ return ret; } if(type->attributes==nullptr) - type->attributes=xbt_dict_new(); + type->attributes = xbt_dict_new_homogeneous(nullptr); xbt_dict_set_ext(type->attributes, reinterpret_cast(&keyval), sizeof(int), attr_value, nullptr); return MPI_SUCCESS; @@ -1630,7 +1633,7 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){ int smpi_type_keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state){ if(smpi_type_keyvals==nullptr) - smpi_type_keyvals = xbt_dict_new(); + smpi_type_keyvals = xbt_dict_new_homogeneous(nullptr); smpi_type_key_elem value = (smpi_type_key_elem) xbt_new0(s_smpi_mpi_type_key_elem_t,1);