int ret=MPI_SUCCESS;
*new_t= xbt_new(s_smpi_mpi_datatype_t,1);
memcpy(*new_t, datatype, sizeof(s_smpi_mpi_datatype_t));
+ (*new_t)->in_use=1;
+ (*new_t)->flags &= ~DT_FLAG_PREDEFINED;
if (datatype->sizeof_substruct){
(*new_t)->substruct=xbt_malloc(datatype->sizeof_substruct);
memcpy((*new_t)->substruct, datatype->substruct, datatype->sizeof_substruct);
if(elem && elem->copy_fn!=MPI_NULL_COPY_FN){
ret = elem->copy_fn(datatype, *key, NULL, value_in, &value_out, &flag );
if(ret!=MPI_SUCCESS){
+ smpi_datatype_unuse(*new_t);
*new_t=MPI_DATATYPE_NULL;
return ret;
}
}
void smpi_datatype_set_name(MPI_Datatype datatype, char* name){
+ if(datatype->name!=NULL && !(datatype->flags & DT_FLAG_PREDEFINED))
+ xbt_free(datatype->name);
datatype->name = xbt_strdup(name);;
}
void smpi_datatype_free(MPI_Datatype* type){
xbt_assert((*type)->in_use >= 0);
+
+ if((*type)->flags & DT_FLAG_PREDEFINED)return;
+
+ //if still used, mark for deletion
+ if((*type)->in_use!=0){
+ (*type)->flags |=DT_FLAG_DESTROYED;
+ return;
+ }
+
if((*type)->attributes !=NULL){
xbt_dict_cursor_t cursor = NULL;
int* key;
}
}
- if((*type)->flags & DT_FLAG_PREDEFINED)return;
-
- //if still used, mark for deletion
- if((*type)->in_use!=0){
- (*type)->flags |=DT_FLAG_DESTROYED;
- return;
- }
-
if ((*type)->sizeof_substruct != 0){
//((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);
xbt_free((*type)->substruct);
}
- if ((*type)->name != NULL){
- xbt_free((*type)->name);
- }
+ xbt_free((*type)->name);
+ xbt_free(*type);
*type = MPI_DATATYPE_NULL;
}
void smpi_datatype_use(MPI_Datatype type){
if(type)type->in_use++;
-XBT_INFO("using type %p, counter %d ", type, type->in_use);
+
if(type->sizeof_substruct!=0){
((s_smpi_subtype_t *)(type)->substruct)->subtype_use(&type);
}
if (type->in_use > 0)
type->in_use--;
-XBT_INFO("unusing type %p, counter %d ", type, type->in_use);
if(type->sizeof_substruct!=0){
((s_smpi_subtype_t *)(type)->substruct)->subtype_free(&type);
}
if(type && type->in_use == 0){
- MPI_Datatype t = type;
- if (!(type->flags & DT_FLAG_DESTROYED))
- smpi_datatype_free(&type);
- if(t->flags & DT_FLAG_PREDEFINED) return;
- xbt_free(t);
+ smpi_datatype_free(&type);
}
#if HAVE_MC
if(MC_is_active())
}
void free_contiguous(MPI_Datatype* d){
- smpi_datatype_unuse(((s_smpi_mpi_indexed_t *)(*d)->substruct)->old_type);
+ smpi_datatype_unuse(((s_smpi_mpi_contiguous_t *)(*d)->substruct)->old_type);
}
void use_contiguous(MPI_Datatype* d){
- smpi_datatype_use(((s_smpi_mpi_indexed_t *)(*d)->substruct)->old_type);
+ smpi_datatype_use(((s_smpi_mpi_contiguous_t *)(*d)->substruct)->old_type);
}
/* Create a Sub type contiguous to be able to serialize and unserialize it the structure s_smpi_mpi_contiguous_t is
//do nothing for vector types
void free_hvector(MPI_Datatype* d){
- smpi_datatype_unuse(((s_smpi_mpi_indexed_t *)(*d)->substruct)->old_type);
+ smpi_datatype_unuse(((s_smpi_mpi_hvector_t *)(*d)->substruct)->old_type);
}
void use_hvector(MPI_Datatype* d){
- smpi_datatype_use(((s_smpi_mpi_indexed_t *)(*d)->substruct)->old_type);
+ smpi_datatype_use(((s_smpi_mpi_hvector_t *)(*d)->substruct)->old_type);
}
int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
new_t->base.unserialize = &unserialize_indexed;
new_t->base.subtype_free = &free_indexed;
new_t->base.subtype_use = &use_indexed;
- //TODO : add a custom function for each time to clean these
new_t->block_lengths= xbt_new(int, block_count);
new_t->block_indices= xbt_new(int, block_count);
int i;
}
void use_hindexed(MPI_Datatype* type){
- smpi_datatype_use(((s_smpi_mpi_indexed_t *)(*type)->substruct)->old_type);
+ smpi_datatype_use(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->old_type);
}
/* Create a Sub type hindexed to be able to serialize and unserialize it the structure s_smpi_mpi_hindexed_t is derived
new_t->base.unserialize = &unserialize_hindexed;
new_t->base.subtype_free = &free_hindexed;
new_t->base.subtype_use = &use_hindexed;
- //TODO : add a custom function for each time to clean these
new_t->block_lengths= xbt_new(int, block_count);
new_t->block_indices= xbt_new(MPI_Aint, block_count);
int i;
new_t->base.unserialize = &unserialize_struct;
new_t->base.subtype_free = &free_struct;
new_t->base.subtype_use = &use_struct;
- //TODO : add a custom function for each time to clean these
new_t->block_lengths= xbt_new(int, block_count);
new_t->block_indices= xbt_new(MPI_Aint, block_count);
new_t->old_types= xbt_new(MPI_Datatype, block_count);
new_t->old_types[i]=old_types[i];
smpi_datatype_use(new_t->old_types[i]);
}
- //new_t->block_lengths = block_lengths;
- //new_t->block_indices = block_indices;
new_t->block_count = block_count;
- //new_t->old_types = old_types;
return new_t;
}