Note that there are some explanatory texts on larger screens.

plurals
  1. POHalo exchange not working properly in MPI
    text
    copied!<p>I'm writing some code which does calculations on a large 3D grid, and uses a halo exchange procedure so that it can work using MPI. I'm getting the wrong results from my code, and I'm pretty sure it's because of the halo exchange not working properly.</p> <p>Basically I have a large 3D array, a chunk of which is held on each process. Each process has an array which is 2 elements bigger in each dimension than the chunk of data it is holding - so that we can halo exchange into each face of the array without affecting the data stored in the rest of the array. I have the following code to do the halo exchange communication:</p> <pre><code> MPI_Type_vector(g-&gt;ny, g-&gt;nx, g-&gt;nx, MPI_DOUBLE, &amp;face1); MPI_Type_commit(&amp;face1); MPI_Type_vector(2*g-&gt;ny, 1, g-&gt;nx, MPI_DOUBLE, &amp;face2); MPI_Type_commit(&amp;face2); MPI_Type_vector(g-&gt;nz, g-&gt;nx, g-&gt;nx * g-&gt;ny, MPI_DOUBLE, &amp;face3); MPI_Type_commit(&amp;face3); /* Send to WEST receive from EAST */ MPI_Sendrecv(&amp;(g-&gt;data)[current][0][0][0], 1, face1, g-&gt;west, tag, &amp;(g-&gt;data)[current][0][0][0], 1, face1, g-&gt;east, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* Send to EAST receive from WEST */ MPI_Sendrecv(&amp;(g-&gt;data)[current][g-&gt;nz-1][0][0], 1, face1, g-&gt;east, tag, &amp;(g-&gt;data)[current][g-&gt;nz-1][0][0], 1, face1, g-&gt;west, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* Send to NORTH receive from SOUTH */ MPI_Sendrecv(&amp;(g-&gt;data)[current][0][0][0], 1, face2, g-&gt;north, tag, &amp;(g-&gt;data)[current][0][0][0], 1, face2, g-&gt;south, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* Send to SOUTH receive from NORTH */ MPI_Sendrecv(&amp;(g-&gt;data)[current][0][g-&gt;ny-1][0], 1, face2, g-&gt;south, tag, &amp;(g-&gt;data)[current][0][0][0], 1, face2, g-&gt;north, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* Send to UP receive from DOWN */ MPI_Sendrecv(&amp;(g-&gt;data)[current][0][0][0], 1, face3, g-&gt;up, tag, &amp;(g-&gt;data)[current][0][0][0], 1, face3, g-&gt;down, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* Send to DOWN receive from UP */ MPI_Sendrecv(&amp;(g-&gt;data)[current][0][0][g-&gt;nx-1], 1, face3, g-&gt;down, tag, &amp;(g-&gt;data)[current][0][0][g-&gt;nx-1], 1, face3, g-&gt;up, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); </code></pre> <p><code>g-&gt;nx</code>, <code>g-&gt;ny</code> and <code>g-&gt;nz</code> are the sizes of the array chunk that this process is holding, and <code>g-&gt;west</code>, <code>g-&gt;east</code>, <code>g-&gt;north</code>, <code>g-&gt;south</code>, <code>g-&gt;up</code> and <code>g-&gt;down</code> are the ranks of the adjacent processes in each direction, found using the following code:</p> <pre><code>/* Who are my neighbours in each direction? */ MPI_Cart_shift( cart_comm, 2, 1, &amp;g-&gt;north, &amp;g-&gt;south); MPI_Cart_shift( cart_comm, 1, 1, &amp;g-&gt;west, &amp;g-&gt;east); MPI_Cart_shift( cart_comm, 0, 1, &amp;g-&gt;up, &amp;g-&gt;down); </code></pre> <p>The array on each process is defined as:</p> <pre><code>array[2][g-&gt;nz][g-&gt;ny][g-&gt;nx] </code></pre> <p>(It has two copies because I need one to update into each time through my update routine, once I've done the halo exchange).</p> <p>Can anyone tell me if I'm doing the communication correctly? Particularly the defining of the vector types. Will the vector types I've defined in the code extract each face of a 3D array? And do the MPI_Sendrecv calls look right?</p> <p>I'm completely lost as to why my code isn't working, but I'm pretty sure it's communications related.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload