I have a 3D array Foo3D
(50 x 100 x 100) in ranks 0 and 1. Foo3D
is allocated like this:
int nx = 50;
int ny = 100;
int nz = 100;
typedef int nRarray[100][50];
nRarray *Foo3D;
if ((Foo3D = (nRarray *)malloc((nx*ny*nz)*sizeof(int))) == 0) {fprintf(stderr,"malloc1 Fail \n"); return 1;}
I assign some numbers to Foo3D
in rank 0 and save it to a new 2D array (Foo2D
) as:
if (myrank == 0) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
Foo3D[0][j][k] = j + k;
Foo2D[j][k] = Foo3D[0][j][k];
}
}
}
Now, I'm interested to send Foo2D
to rank 1, and place it in its position in Foo3D
. In fact, I know I can send Foo2D
to rank 1 as:
if (myrank == 0)
{
MPI_Send(Foo2D,sizeof_Foo2D,MPI_INT,1,100,MPI_COMM_WORLD);
}
else if (myrank == 1)
{
MPI_Recv(Foo2D,sizeof_Foo2D,MPI_INT,0,100,MPI_COMM_WORLD, &status);
}
And then assign the received Foo2D
in rank 1 to its position in Foo3D
as:
if (myrank == 1)
{
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
Foo3D[0][j][k] = Foo2D[j][k];
}
}
}
Instead of using this procedure and Foo2D
as an intermediate variable, is it possible to send the slice of Foo3D
in rank 0 directly to its equivalent position in rank 1 or not? In fact, I don't want to send the whole Foo3D
to rank 1 because it's a really large array and I'm interested to send just a slice of it to rank 1.