The solution given here puts the MPI_Request for each operation into an array r and uses the integer nreq to keep track of how many requests are used (Why? What happens at the edges of the mesh?) Another approach is to use fixed locations in r, but use MPI_REQUEST_NULL as the value for the send or receive operations that are not done. Alternately, a source or destination of MPI_PROC_NULL can be used in the MPI_Isend or MPI_Irecv.