nbrs = u[i+1][j+1] + u[i+1][j] + u[i+1][j-1] +
u[i][j+1] + u[i][j-1] +
u[i-1][j+1] + u[i-1][j] + u[i-1][j-1];
Thanks to Yang Shangqin.
Thanks to Chan Park.
MPI_Aint sdispls[4] = ind(1,1), ind(1,by), ind(bx,1),
ind(1,1),
rdispls[4] = ind(1,0), ind(1,by+1), ind(bx+1,1),
ind(0,1);
with these
MPI_Aint extent, lb;
MPI_Type_get_extent(MPI_DOUBLE, &lb, &extent);
MPI_Aint sdispls[4] = ind(1,1)*extent, ind(1,by)*extent,
ind(1,1)*extent, ind(bx,1)*extent;
MPI_Aint rdispls[4] = ind(1,0)*extent, ind(1,by+1)*extent,
ind(0,1)*extent, ind(bx+1,1)*extent;
Thanks to Chan Park.
Thanks to Chan Park.
To use the MCS lock code, make sure that asynchronous progress is enabled in your MPI implementation. For MPICH, for example, this is done by setting the variable MPIR_CVAR_ASYNC_PROGRESS=1 (and also building MPICH to support asynchronous progress). There is some evidence that some implementations still have problems with asynchronous progress, even when this is requested.
For implementations that do not correctly support asynchronous progress, the most common workaround is for each process to periodically call some MPI communication routine, such as MPI_Iprobe. In the case of the MCS lock release code, there is this block of code:
if (lmem[nextRank] == -1) { If-Block; // starts with MPI_Compare_and_swap(...) }The test in this code is used to avoid an unnecessary MPI communication operation; specifically, the MPI_Compare_and_swap call. However, because of the way that this code is written, the operation of the code is correct if the ``If-Block'' is unconditionally executed. In addition, the compare-and-swap call serves as an MPI communication call, so if asynchronous progress is not supported, unconditionally executing the ``If-Block'' can help (though not guarantee, depending on timing) the code to work properly.
if (err != MPI_SUCCESS) MPI_Abort(MPI_COMM_WORLD, 0);
Thanks to Chen-Yi GAO.
and is available for download as advmpi-spawn.pdf .
Thanks to Jeff Hammond.
... call mpi_comm_dup(MPI_COMM_WORLD, comm) call mpi_type_contiguous(100, MPI_REAL, rtype) call mpi_type_commit(rtype) call mpi_comm_rank(comm, myrank) ...