Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / smpi_group.c
index a88bcca..2e0125e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010. The SimGrid Team.
+/* Copyright (c) 2010, 2013. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -48,21 +48,26 @@ MPI_Group smpi_group_new(int size)
 
 MPI_Group smpi_group_copy(MPI_Group origin)
 {
-  MPI_Group group;
+  MPI_Group group=origin;
   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;
 }
@@ -70,7 +75,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 +86,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 +118,15 @@ int smpi_group_use(MPI_Group group)
 
 int smpi_group_unuse(MPI_Group group)
 {
-  if (group->refcount-- <= 0) {
-    XBT_VERB("freeing group %p", group);
+  group->refcount--;
+  if (group->refcount <= 0) {
     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)