!4. Modify example4.f90 to update RHS guard cells. !----------------------------------------------------------- program main !-- On a 1D grid of 4 blocks. Each block updates its guard ! cells (v0 and v3) with data from its left and ! right neighbors. implicit none !--Include the mpi header file include 'mpif.h' integer i,ierr,my_rank,numprocs,itag integer message,mess_received,iroot_pe,itag,icount,ierror integer status(MPI_STATUS_SIZE) integer irc integer sendtag,recvtag parameter (ndims=1) !dimension of the Cartesian grid integer ndims,dims(ndims) logical periods(ndims),reorder integer comm_cart integer coords(ndims),neig_coords(ndims) integer direction,disp,source,dest integer MPI_PROC_NULL real vel(0:3),v0,v3 !MODIFIED! !--Initialize MPI call MPI_INIT( ierr ) !--Who am I? --- get my rank=my_rank call MPI_COMM_RANK( MPI_COMM_WORLD, my_rank, ierr ) !--How many processes in the global group? call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr ) print *, "Process ", my_rank, " of ", numprocs, " is alive" !--Create a Cartesian topology dims(1:ndims)=4 periods=.true. reorder=.false. call MPI_CART_CREATE(MPI_COMM_WORLD,ndims,dims,periods, & & reorder,comm_cart,ierror) !--Find rank of left and right (along x) blocks direction=0 !(along x) disp=-1 !MODIFIED! !immediate neighbors call MPI_CART_SHIFT(comm_cart,direction,disp,source, & & dest,ierror) write(*,*)'my_rank=',my_rank,' source=',source,' dest=',dest !--Am I at a physical boundary? if (dest==MPI_PROC_NULL) & write(*,*)'dest=MPI_PROC_NULL at proc ',my_rank if (source==MPI_PROC_NULL) & write(*,*)'source=MPI_PROC_NULL at proc ',my_rank !--Find the coordinate parameters of this block call MPI_CART_COORDS(comm_cart,my_rank,ndims,coords,ierror) !--Assign some values to vel(0:2) do i=0,2 vel(i)=float(i+100*coords(1)) end do !--Send vel(1) to the block to my left and receive v3 from my right -->Modified sendtag=1 recvtag=1 call MPI_SENDRECV(vel(1),1,MPI_REAL,dest,sendtag, & !MODIFIED! v3,1,MPI_REAL,source,recvtag, & !MODIFIED! comm_cart,status,ierror) !--Print out the updated v3 write(*,*)'my coords are: ',coords,' v3= ',v3 !MODIFIED! !--Finilize MPI call MPI_FINALIZE(irc) stop end