l***@yahoo.com
2008-01-29 10:24:54 UTC
Hi all,
I'm wondering if it is possible to create an array of groups/
communicators. Say I have 9 processors, and I want to create 8 groups,
as shown below
(new_group : processors in that group)
new_group[0] : 0 1 2 3 4 5 6 7 8
new_group[1] : 1 2 3 4 5 6 7 8
new_group[2] : 2 3 4 5 6 7 8
new_group[3] : 3 4 5 6 7 8
new_group[4] : 4 5 6 7 8
new_group[5] : 5 6 7 8
new_group[6] : 6 7 8
new_group[7] : 7 8
The reason why I need the processors to be grouped this way is so I
can broadcast from the first processor in each group to the rest of
the processors, and the number of processors and the processors
involved in each broadcast varies as shown.
Here's what I have:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define p 9
int main(int argc, char** argv)
{
int rank, i, j, k, **ranks, no_procs[p-1];
MPI_Group orig_group, new_group[p-1];
MPI_Comm new_comm[p-1];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_group(MPI_COMM_WORLD, &orig_group);
ranks = (int**)calloc(p-1, sizeof(int*));
for (i = 0 ; i < (p-1) ; i++)
ranks[i] = (int*)calloc(p-i, sizeof(int));
for (i = 0 ; i < (p-1) ; i++)
{
no_procs[i] = p-i;
for (j = i ; j < p ; j++)
ranks[i][j] = j;
}
for (i = 0 ; i < (p-1) ; i++)
{
MPI_Group_incl(orig_group, no_procs[i], ranks[i],
&new_group[i]);
MPI_Comm_create(MPI_COMM_WORLD, new_group[i], &new_comm[i]);
}
for (i = 0 ; i < (p-1) ; i++)
free(ranks[i]);
free(ranks);
MPI_Finalize();
return 0;
}
I keep getting the segmentation fault error right before the
MPI_Group_incl(orig_group, no_procs[i], ranks[i], &new_group[i]);
line. What am I getting wrong here?
Thank you.
Regards,
Rayne
I'm wondering if it is possible to create an array of groups/
communicators. Say I have 9 processors, and I want to create 8 groups,
as shown below
(new_group : processors in that group)
new_group[0] : 0 1 2 3 4 5 6 7 8
new_group[1] : 1 2 3 4 5 6 7 8
new_group[2] : 2 3 4 5 6 7 8
new_group[3] : 3 4 5 6 7 8
new_group[4] : 4 5 6 7 8
new_group[5] : 5 6 7 8
new_group[6] : 6 7 8
new_group[7] : 7 8
The reason why I need the processors to be grouped this way is so I
can broadcast from the first processor in each group to the rest of
the processors, and the number of processors and the processors
involved in each broadcast varies as shown.
Here's what I have:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define p 9
int main(int argc, char** argv)
{
int rank, i, j, k, **ranks, no_procs[p-1];
MPI_Group orig_group, new_group[p-1];
MPI_Comm new_comm[p-1];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_group(MPI_COMM_WORLD, &orig_group);
ranks = (int**)calloc(p-1, sizeof(int*));
for (i = 0 ; i < (p-1) ; i++)
ranks[i] = (int*)calloc(p-i, sizeof(int));
for (i = 0 ; i < (p-1) ; i++)
{
no_procs[i] = p-i;
for (j = i ; j < p ; j++)
ranks[i][j] = j;
}
for (i = 0 ; i < (p-1) ; i++)
{
MPI_Group_incl(orig_group, no_procs[i], ranks[i],
&new_group[i]);
MPI_Comm_create(MPI_COMM_WORLD, new_group[i], &new_comm[i]);
}
for (i = 0 ; i < (p-1) ; i++)
free(ranks[i]);
free(ranks);
MPI_Finalize();
return 0;
}
I keep getting the segmentation fault error right before the
MPI_Group_incl(orig_group, no_procs[i], ranks[i], &new_group[i]);
line. What am I getting wrong here?
Thank you.
Regards,
Rayne