I’m working on a project which contains several slave nodes and one master node. At some point I need to gather data from different slave nodes(master node can be treated as a slave node too) to master node. The data can be any type but let’s suppose it is unsigned int. And that is how the data looks on slave nodes:
node0: |chunk01|chunk02|chunk03|chunk04|….
node1: |chunk11|chunk12|chunk13|chunk14|….
…
noden: |chunkn1|chunkn2|chunkn3|chunkn4|….
The data should be all gathered to node0 and look like this:
node0: |chunk01|chunk11|chunk21|….|chunkn1|chunk02|chunk12|…|chunkn2|…|chunknm|
Which means we concatenate the first chunk from each node together, then second chunk from each node together…
I don’t know how to use MPI_Gatherv to implement this because each chunkij has different size, also each node only knows its own chunk size and start index, but not other node’s info.
I’m not so familiar with MPI so I’m wondering is there any API which can gather data of different size from various nodes to one node?
Here’s an example that you can edit that should work. It is almost certainly not the most optimal way to solve the problem – I’d need more details of your code to comment on that. I haven’t checked whether it compiles, but if you fix up any typos I’m happy to try to fix any outstanding bugs.
I also don’t know how important efficiency is to you – is this op going to be done hundreds of times per second or once a day? If it’s the latter, then this code is probably fine. I’m also assuming C / C++.