How 2D array goes through in MPJ (other than object shape)

I want to send an adjacency matrix via MPJ, and one solution to this is to send a 2-dimensional array in the form of an object, and the second solution is to send a 2-dimensional array as a one-dimensional array, i.e. [N * N].

However, I want to send a 2-dimensional array in its original form - is MPJ supported? If so, how should I approach it?

+3


source to share


1 answer


My favorite approach would be to send the 2D array as a 1D array of objects, where each object is a 1D array.

For example, if you want to send int A[M][N]

, you can simply do

MPI.COMM_WORLD.Send(A, 0, M, MPI.OBJECT, TARGET_ID, MESSAGE_ID);

      

To receive, you can create a buffer first and then use MPI Receive:



int buffer[][] = new int[M][N];
MPI.COMM_WORLD.Send(buffer, 0, M, MPI.OBJECT, SENDER_ID, MESSAGE_ID);

      

Note that the offset and length in your MPI commands correspond to the index of the outermost array.

Hope it helps!

+1


source







All Articles