0

I am new in MPI I have some arrays generated by processors. Each processor generated one array with DIFFERENT length. How can I merging all of them IN ORDER in to one array only stored in processor 0.

Eg:

Processor 0: [1 1 1]
Processor 1: [2 2 2]
Processor 2: [3 3 3 3 3]
And my expected result is [1 1 1 2 2 2 3 3 3 3 3], not [1 1 1 3 3 3 3 3 2 2 2]

Is there anyone can help me solve this problem. Thank for reading :)

Liverpool
  • 131
  • 7
  • 12

1 Answers1

0

If the sizes of each ranks contribution are known ahead of time, MPI_Gatherv will do the job in a single collective.

If the sizes of each ranks contribution are not known ahead of time, the point to point operations (MPI_Send, with MPI_Probe and MPI_Recv) will be a straightforward way to accomplish this. The root can serialize the MPI_Recv operations, and allocate the space as the operation proceeds.

Stan Graves
  • 6,795
  • 2
  • 18
  • 14