+ index = this->index(ranks[i]);
+ (*newgroup)->set_mapping(index, i);
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::group_union(MPI_Group group2, MPI_Group* newgroup)
+{
+ int size1 = m_size;
+ int size2 = group2->size();
+ for (int i = 0; i < size2; i++) {
+ int proc2 = group2->index(i);
+ int proc1 = this->rank(proc2);
+ if (proc1 == MPI_UNDEFINED) {
+ size1++;
+ }
+ }
+ if (size1 == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(size1);
+ size2 = this->size();
+ for (int i = 0; i < size2; i++) {
+ int proc1 = this->index(i);
+ (*newgroup)->set_mapping(proc1, i);
+ }
+ for (int i = size2; i < size1; i++) {
+ int proc2 = group2->index(i - size2);
+ (*newgroup)->set_mapping(proc2, i);
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::intersection(MPI_Group group2, MPI_Group* newgroup)
+{
+ int size2 = group2->size();
+ for (int i = 0; i < size2; i++) {
+ int proc2 = group2->index(i);
+ int proc1 = this->rank(proc2);
+ if (proc1 == MPI_UNDEFINED) {
+ size2--;
+ }
+ }
+ if (size2 == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(size2);
+ int j=0;
+ for (int i = 0; i < group2->size(); i++) {
+ int proc2 = group2->index(i);
+ int proc1 = this->rank(proc2);
+ if (proc1 != MPI_UNDEFINED) {
+ (*newgroup)->set_mapping(proc2, j);
+ j++;
+ }
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::difference(MPI_Group group2, MPI_Group* newgroup)
+{
+ int newsize = m_size;
+ int size2 = m_size;
+ for (int i = 0; i < size2; i++) {
+ int proc1 = this->index(i);
+ int proc2 = group2->rank(proc1);
+ if (proc2 != MPI_UNDEFINED) {
+ newsize--;
+ }
+ }
+ if (newsize == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ for (int i = 0; i < size2; i++) {
+ int proc1 = this->index(i);
+ int proc2 = group2->rank(proc1);
+ if (proc2 == MPI_UNDEFINED) {
+ (*newgroup)->set_mapping(proc1, i);
+ }
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::excl(int n, int *ranks, MPI_Group * newgroup){
+ int oldsize = m_size;
+ int newsize = oldsize - n;
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ int* to_exclude=xbt_new0(int, m_size);
+ for (int i = 0; i < oldsize; i++)
+ to_exclude[i]=0;
+ for (int i = 0; i < n; i++)
+ to_exclude[ranks[i]]=1;
+ int j = 0;
+ for (int i = 0; i < oldsize; i++) {
+ if(to_exclude[i]==0){
+ int index = this->index(i);
+ (*newgroup)->set_mapping(index, j);
+ j++;
+ }
+ }
+ xbt_free(to_exclude);
+ return MPI_SUCCESS;
+
+}
+
+int Group::range_incl(int n, int ranges[][3], MPI_Group * newgroup){
+ int newsize = 0;
+ for (int i = 0; i < n; i++) {
+ for (int rank = ranges[i][0]; /* First */
+ rank >= 0 && rank < m_size; /* Last */
+ ) {
+ newsize++;
+ if(rank == ranges[i][1]){/*already last ?*/
+ break;
+ }
+ rank += ranges[i][2]; /* Stride */
+ if (ranges[i][0] < ranges[i][1]) {
+ if (rank > ranges[i][1])
+ break;
+ } else {
+ if (rank < ranges[i][1])
+ break;
+ }
+ }
+ }
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ int j = 0;
+ for (int i = 0; i < n; i++) {
+ for (int rank = ranges[i][0]; /* First */
+ rank >= 0 && rank < m_size; /* Last */
+ ) {
+ int index = this->index(rank);
+ (*newgroup)->set_mapping(index, j);
+ j++;
+ if(rank == ranges[i][1]){/*already last ?*/
+ break;
+ }
+ rank += ranges[i][2]; /* Stride */
+ if (ranges[i][0] < ranges[i][1]) {
+ if (rank > ranges[i][1])
+ break;
+ } else {
+ if (rank < ranges[i][1])
+ break;
+ }