MPI: how to combine subarrays in several processors into a larger single array

I use MPI in C. I was able to distribute the parts of the array to different processors. And different processors did all the manipulations I wanted. Now I am at the point where I wanted to combine all the subarrays that are in all processors into one large array. For example, if different processors had subtasks as follows:

Processor 1: 0 1 1 0 0 0 1 0 Processor 2: 0 0 1 0 1 1 0 1 Processor 3: 1 1 0 0 1 1 1 1 ... 

I want to merge or merge all subarrays together. For example, I would like a large array to be:

 0 1 1 0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 0 0 1 1 1 1 ... 

I tried to use MPI_Reduce, but I could not find the operation to do what I wanted to do. Is there any other MPI method that I could use to achieve what I'm looking for?

+4
source share
1 answer

You are looking for MPI_Gather:

Each process (the included root process) sends the contents of its send buffer to the root process. The root process receives messages and stores them in ranking order.

For documentation and examples, see here and here . Section 5.5 in MPI 2.2 Standard also has examples.

+1
source

All Articles