From: Augustin Degomme Date: Thu, 11 Jul 2013 16:47:06 +0000 (+0200) Subject: remove a few leaks and memory errors X-Git-Tag: v3_9_90~151 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/51f94e1d38869bd7a057c58ff4978fdff170a6e6 remove a few leaks and memory errors --- diff --git a/src/smpi/smpi_comm.c b/src/smpi/smpi_comm.c index 2f6bf15997..0cb342fc21 100644 --- a/src/smpi/smpi_comm.c +++ b/src/smpi/smpi_comm.c @@ -132,7 +132,6 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key) } for(j = 0; j < count; j++) { //increment refcounter in order to avoid freeing the group too quick before copy - smpi_group_use(group_out); index = smpi_group_index(group, rankmap[2 * j]); smpi_group_set_mapping(group_out, index, j); } @@ -150,13 +149,11 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key) } xbt_free(recvbuf); group_out = group_root; /* exit with root's group */ - if(group_out)smpi_group_unuse(group_out); } else { if(color != MPI_UNDEFINED) { smpi_mpi_recv(&group_out, 1, MPI_PTR, 0, system_tag, comm, MPI_STATUS_IGNORE); if(group_out){ group_out=smpi_group_copy(group_out); - smpi_group_unuse(group_out); } } /* otherwise, exit with group_out == NULL */ } diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 659388c376..7cf9d544e4 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -280,11 +280,11 @@ void smpi_global_destroy(void) int i; smpi_bench_destroy(); - smpi_group_destroy(smpi_comm_group(MPI_COMM_WORLD)); + smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)); smpi_comm_destroy(MPI_COMM_WORLD); MPI_COMM_WORLD = MPI_COMM_NULL; for (i = 0; i < count; i++) { - smpi_group_destroy(smpi_comm_group(process_data[i]->comm_self)); + smpi_group_unuse(smpi_comm_group(process_data[i]->comm_self)); smpi_comm_destroy(process_data[i]->comm_self); xbt_os_timer_free(process_data[i]->timer); simcall_rdv_destroy(process_data[i]->mailbox); diff --git a/src/smpi/smpi_group.c b/src/smpi/smpi_group.c index a88bccad3f..89f0f186ca 100644 --- a/src/smpi/smpi_group.c +++ b/src/smpi/smpi_group.c @@ -50,19 +50,24 @@ MPI_Group smpi_group_copy(MPI_Group origin) { MPI_Group group; int i, count; - - count = smpi_process_count(); - group = xbt_new(s_smpi_mpi_group_t, 1); - group->size = origin->size; - group->rank_to_index_map = xbt_new(int, group->size); - group->index_to_rank_map = xbt_new(int, count); - group->refcount = 1; - for (i = 0; i < group->size; i++) { - group->rank_to_index_map[i] = origin->rank_to_index_map[i]; - } - for (i = 0; i < count; i++) { - group->index_to_rank_map[i] = origin->index_to_rank_map[i]; - } + if(origin!= smpi_comm_group(MPI_COMM_WORLD) + && origin != MPI_GROUP_NULL + && origin != smpi_comm_group(MPI_COMM_SELF) + && origin != MPI_GROUP_EMPTY) + { + count = smpi_process_count(); + group = xbt_new(s_smpi_mpi_group_t, 1); + group->size = origin->size; + group->rank_to_index_map = xbt_new(int, group->size); + group->index_to_rank_map = xbt_new(int, count); + group->refcount = 1; + for (i = 0; i < group->size; i++) { + group->rank_to_index_map[i] = origin->rank_to_index_map[i]; + } + for (i = 0; i < count; i++) { + group->index_to_rank_map[i] = origin->index_to_rank_map[i]; + } + } return group; } @@ -71,6 +76,10 @@ MPI_Group smpi_group_copy(MPI_Group origin) void smpi_group_destroy(MPI_Group group) { XBT_VERB("trying to free group %p, refcount = %d", group, group->refcount); + if(group!= smpi_comm_group(MPI_COMM_WORLD) + && group != MPI_GROUP_NULL + && group != smpi_comm_group(MPI_COMM_SELF) + && group != MPI_GROUP_EMPTY) smpi_group_unuse(group); } @@ -78,7 +87,7 @@ void smpi_group_set_mapping(MPI_Group group, int index, int rank) { if (rank < group->size && index < smpi_process_count()) { group->rank_to_index_map[rank] = index; - group->index_to_rank_map[index] = rank; + if(index!=MPI_UNDEFINED)group->index_to_rank_map[index] = rank; } } @@ -110,13 +119,16 @@ int smpi_group_use(MPI_Group group) int smpi_group_unuse(MPI_Group group) { - if (group->refcount-- <= 0) { + group->refcount--; + if (group->refcount <= 0) { XBT_VERB("freeing group %p", group); xbt_free(group->rank_to_index_map); xbt_free(group->index_to_rank_map); xbt_free(group); + return 0; } return group->refcount; + } int smpi_group_size(MPI_Group group) diff --git a/src/smpi/smpi_pmpi.c b/src/smpi/smpi_pmpi.c index f073ed7a5d..8feabeee1b 100644 --- a/src/smpi/smpi_pmpi.c +++ b/src/smpi/smpi_pmpi.c @@ -303,7 +303,6 @@ int PMPI_Group_free(MPI_Group * group) if (group == NULL) { retval = MPI_ERR_ARG; } else { - if(*group!= smpi_comm_group(MPI_COMM_WORLD))// do not free the group of the comm_world smpi_group_destroy(*group); *group = MPI_GROUP_NULL; retval = MPI_SUCCESS; @@ -419,7 +418,6 @@ int PMPI_Group_union(MPI_Group group1, MPI_Group group2, smpi_group_set_mapping(*newgroup, proc2, i); } } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } smpi_bench_begin(); @@ -459,7 +457,6 @@ int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, } } } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } smpi_bench_begin(); @@ -496,7 +493,6 @@ int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgro } } } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } smpi_bench_begin(); @@ -517,6 +513,11 @@ int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup) *newgroup = MPI_GROUP_EMPTY; } else if (n == smpi_group_size(group)) { *newgroup = group; + if(group!= smpi_comm_group(MPI_COMM_WORLD) + && group != MPI_GROUP_NULL + && group != smpi_comm_group(MPI_COMM_SELF) + && group != MPI_GROUP_EMPTY) + smpi_group_use(group); } else { *newgroup = smpi_group_new(n); for (i = 0; i < n; i++) { @@ -524,7 +525,6 @@ int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup) smpi_group_set_mapping(*newgroup, index, i); } } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } smpi_bench_begin(); @@ -543,6 +543,11 @@ int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup) } else { if (n == 0) { *newgroup = group; + if(group!= smpi_comm_group(MPI_COMM_WORLD) + && group != MPI_GROUP_NULL + && group != smpi_comm_group(MPI_COMM_SELF) + && group != MPI_GROUP_EMPTY) + smpi_group_use(group); } else if (n == smpi_group_size(group)) { *newgroup = MPI_GROUP_EMPTY; } else { @@ -567,7 +572,6 @@ int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup) xbt_free(to_exclude); } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } smpi_bench_begin(); @@ -626,7 +630,6 @@ int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], } } } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } smpi_bench_begin(); @@ -646,6 +649,11 @@ int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], } else { if (n == 0) { *newgroup = group; + if(group!= smpi_comm_group(MPI_COMM_WORLD) + && group != MPI_GROUP_NULL + && group != smpi_comm_group(MPI_COMM_SELF) + && group != MPI_GROUP_EMPTY) + smpi_group_use(group); } else { size = smpi_group_size(group); for (i = 0; i < n; i++) { @@ -699,7 +707,6 @@ int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], } } } - smpi_group_use(*newgroup); retval = MPI_SUCCESS; } @@ -769,6 +776,11 @@ int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group) retval = MPI_ERR_ARG; } else { *group = smpi_comm_group(comm); + if(*group!= smpi_comm_group(MPI_COMM_WORLD) + && *group != MPI_GROUP_NULL + && *group != smpi_comm_group(MPI_COMM_SELF) + && *group != MPI_GROUP_EMPTY) + smpi_group_use(*group); retval = MPI_SUCCESS; } smpi_bench_begin();