Neorem
Neorem

Reputation: 71

Is there a way to use MPI_Reduce with dynamic size of send buffer?

I would like to use the "MPI_Reduce" function with a variable number of elements for each process.

For example.

We have 4 processes with an allocated buffer with a dynamic size.

P (0) size buffer = 21

P (1) size buffer = 24

P (2) size buffer = 21

P (3) size buffer = 12

I would like to reduce the values ​​of these elements on the processor with rank 0.

In my thoughts I would like to allocate a receive buffer of a size equal to the maximum of objects to be received by a process (in this case 24) and use that to retrieve the values ​​from the various processes.

There is a way in which is it possible to do without increasing the execution times too much?

I am using Open MPI 2.1.1 in C, Thanks.

Upvotes: 1

Views: 342

Answers (1)

dabo42
dabo42

Reputation: 486

There is no reduction variant that works with different numbers of elements per rank in MPI. It wouldn't know what to fill in for missing operands in the reduction operation. It's pretty straightforward to write though, just as you suggested:

  • Determine the maximum buffer size
  • Allocate max-sized buffer on each rank, copy in local buffer, pad with whatever the neutral element of your reduction operation is
  • Run reduction on the now equal-sized buffers

Upvotes: 1

Related Questions