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

我最喜欢的方法是将二维数组作为一维对象数组发送,其中每个对象都是一维数组。

例如,如果你想发送int A[M][N],你可以简单地做

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

要接收,可以先创建一个缓冲区,然后使用 MPI Receive:

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

请注意,MPI 命令中的偏移量和长度对应于最外层数组的索引。

希望能帮助到你!

于 2014-11-28T21:08:24.537 回答