I'm working on a MPI C program that compute a relaxed state of a hotplate by averaging it's neighbors. So, edge's of each processor need the values from the neighboring proccessor. The problem is fairly basic, but I'm struggling to efficiently use the MPI_SendRecv in two dimensions.
I currently have a 2D grid of processors and each processor has it's own grid of 2D floats of values. After each averaging, processors have to send their edge values (I will be vary the number of rows/cols to send to find optimal sizes given the bandwidth/processing power of different setups once it's all working) to the processor next to him. I've been trying to do all my homework on how to send and recieve, but hit a snag.
MPI_SendRecv does best with contiguous blocks of memory, so I can have each processor allocate their needed size (+padding to store neighboring values). If I broke my hotplate up into meta-rows and passed the last three rows to the neighbor, it would be easy. But my problem has processors not just above and below, but left and right in the 2D array.
So far, the best way I could come up with is to copy the right (x) number of columns into a new contiguous block of memory and then ship that contiguous block to the processor to my right and have that processor copy those values into the 2d array that it has, but this seems super inefficient in my mind. The second option I could think of was to have a second block with the same values but organized by columns instead of rows, but any write would require writing to two places.
Is there a more efficient way? Does this problem have a name that I could research more on? Are there any MPI ways to do this that I haven't found yet?
Thanks!