X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/539916de848562683cf2e5425d5160c2a43f135a..e9f0018b823e34405847177b25a85d3facc30ae1:/src/smpi/smpi_mpi_dt.c diff --git a/src/smpi/smpi_mpi_dt.c b/src/smpi/smpi_mpi_dt.c index 4692a2bd19..bb63c6bc69 100644 --- a/src/smpi/smpi_mpi_dt.c +++ b/src/smpi/smpi_mpi_dt.c @@ -1,7 +1,7 @@ /* smpi_mpi_dt.c -- MPI primitives to handle datatypes */ /* FIXME: a very incomplete implementation */ -/* Copyright (c) 2009-2014. The SimGrid Team. +/* Copyright (c) 2009-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -23,31 +23,33 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi_dt, smpi, xbt_dict_t smpi_type_keyvals = NULL; int type_keyval_id=0;//avoid collisions -#define CREATE_MPI_DATATYPE(name, type) \ - static s_smpi_mpi_datatype_t mpi_##name = { \ +#define CREATE_MPI_DATATYPE(name, type) \ + static s_smpi_mpi_datatype_t mpi_##name = { \ (char*) # name, \ - sizeof(type), /* size */ \ - 0, /*was 1 has_subtype*/ \ - 0, /* lb */ \ - sizeof(type), /* ub = lb + size */ \ - DT_FLAG_BASIC, /* flags */ \ - NULL, /* attributes */ \ - NULL, /* pointer on extended struct*/ \ - }; \ -MPI_Datatype name = &mpi_##name; - -#define CREATE_MPI_DATATYPE_NULL(name) \ - static s_smpi_mpi_datatype_t mpi_##name = { \ + sizeof(type), /* size */ \ + 0, /*was 1 has_subtype*/ \ + 0, /* lb */ \ + sizeof(type), /* ub = lb + size */ \ + DT_FLAG_BASIC, /* flags */ \ + NULL, /* attributes */ \ + NULL, /* pointer on extended struct*/ \ + 0 /* in_use counter */ \ + }; \ +const MPI_Datatype name = &mpi_##name; + +#define CREATE_MPI_DATATYPE_NULL(name) \ + static s_smpi_mpi_datatype_t mpi_##name = { \ (char*) # name, \ - 0, /* size */ \ - 0, /*was 1 has_subtype*/ \ - 0, /* lb */ \ - 0, /* ub = lb + size */ \ - DT_FLAG_BASIC, /* flags */ \ - NULL, /* attributes */ \ - NULL /* pointer on extended struct*/ \ - }; \ -MPI_Datatype name = &mpi_##name; + 0, /* size */ \ + 0, /* was 1 has_subtype*/ \ + 0, /* lb */ \ + 0, /* ub = lb + size */ \ + DT_FLAG_BASIC, /* flags */ \ + NULL, /* attributes */ \ + NULL, /* pointer on extended struct*/ \ + 0 /* in_use counter */ \ + }; \ +const MPI_Datatype name = &mpi_##name; //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC. typedef struct { @@ -185,7 +187,7 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t) memcpy((*new_t)->substruct, datatype->substruct, sizeof(s_smpi_mpi_struct_t)); } if(datatype->name) - (*new_t)->name = strdup(datatype->name); + (*new_t)->name = xbt_strdup(datatype->name); if(datatype->attributes !=NULL){ (*new_t)->attributes=xbt_dict_new(); xbt_dict_cursor_t cursor = NULL; @@ -235,7 +237,7 @@ void smpi_datatype_get_name(MPI_Datatype datatype, char* name, int* length){ } void smpi_datatype_set_name(MPI_Datatype datatype, char* name){ - datatype->name = strdup(name);; + datatype->name = xbt_strdup(name);; } int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, @@ -404,6 +406,7 @@ void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int h } void smpi_datatype_free(MPI_Datatype* type){ + xbt_assert((*type)->in_use >= 0); if((*type)->attributes !=NULL){ xbt_dict_cursor_t cursor = NULL; int* key; @@ -446,7 +449,10 @@ void smpi_datatype_use(MPI_Datatype type){ void smpi_datatype_unuse(MPI_Datatype type){ - if(type && type->in_use-- == 0 && (type->flags & DT_FLAG_DESTROYED)) + if (type->in_use > 0) + type->in_use--; + + if(type && type->in_use == 0 && (type->flags & DT_FLAG_DESTROYED)) smpi_datatype_free(&type); #ifdef HAVE_MC @@ -1773,4 +1779,3 @@ int smpi_mpi_unpack(void* inbuf, int insize, int* position, void* outbuf, int ou *position += outcount * size; return MPI_SUCCESS; } -