3

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

However, I wish to send the 2-d array in its original form -- is it supported by MPJ? If so, how should I approach it?

4

1 に答える 1

1

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 wish 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 first create a buffer 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 outer-most array.

Hope it helps!

于 2014-11-28T21:08:24.537 に答える