Discussion:
Receive buffer to MPI_Reduce
(too old to reply)
funceval
2009-08-14 13:54:53 UTC
Permalink
Hi,

Does MPI_Reduce expect us to allocate memory to the receive buffer on
processors other than the root node? Is something like this guaranteed
to work:

int* local_sum = (int*)calloc(sizeof(int), count);
int* total_sum = 0;

//processor 0 is the root node
if (proc_id == 0)
{
total_sum = (int*)calloc(sizeof(int), count);
}

MPI_Reduce(local_sum, total_sum, count, MPI_INT, 0, MPI_COMM_WORLD);

free(local_sum);
if (proc_id == 0)
{
free(total_sum);
}
Gilles
2009-08-15 17:14:10 UTC
Permalink
Hi,
Post by funceval
Hi,
Does MPI_Reduce expect us to allocate memory to the receive buffer on
processors other than the root node?
No, for processes other than the root one, the receive buffer is ignored.

Is something like this guaranteed
Post by funceval
int* local_sum = (int*)calloc(sizeof(int), count);
int* total_sum = 0;
//processor 0 is the root node
if (proc_id == 0)
{
total_sum = (int*)calloc(sizeof(int), count);
}
MPI_Reduce(local_sum, total_sum, count, MPI_INT, 0, MPI_COMM_WORLD);
It should fail, not due to the receive buffer not allocated for processes other than root which is correct, but because there's no operator here. May be MPI_SUM is missing...

Gilles
Post by funceval
free(local_sum);
if (proc_id == 0)
{
free(total_sum);
}
funceval
2009-08-16 20:57:12 UTC
Permalink
Post by Gilles
Post by funceval
//processor 0 is the root node
if (proc_id == 0)
{
    total_sum = (int*)calloc(sizeof(int), count);
}
MPI_Reduce(local_sum, total_sum, count, MPI_INT, 0, MPI_COMM_WORLD);
It should fail, not due to the receive buffer not allocated for processes other than root which is correct, but because there's no operator here. May be MPI_SUM is missing...
That was a typo. Thanks for the answer.

Loading...