program mpi_test2 ! test to show updating for i,j double loop (partial continuous data) for specific req data only ! ie update u(2:6,2:6) values instead of all u values, also for struct data ! FVM use implicit none include "mpif.h" integer, parameter :: size_x=8,size_y=8 integer :: i,j,k,ierr,rank,nprocs,u(size_x,size_y) integer :: jsta,jend,jsta2,jend1,inext,iprev,isend1,irecv1,isend2 integer :: irecv2,is,ie,js,je integer, allocatable :: jjsta(:), jjlen(:),jjreq(:),u_tmp(:,:) INTEGER istatus(MPI_STATUS_SIZE) call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr) call MPI_Comm_size(MPI_COMM_WORLD,nprocs,ierr) allocate (jjsta(0:nprocs-1),jjlen(0:nprocs-1),jjreq(0:nprocs-1)) is=3; ie=6; js=3; je=6 allocate (u_tmp(is:ie,js:je)) do k = 0, nprocs - 1 call para_range(js,je, nprocs, k, jsta, jend) jjsta(k) = jsta jjlen(k) = (ie-is+1) * (jend - jsta + 1) end do call para_range(js, je, nprocs, rank , jsta, jend) do j=jsta,jend do i=is,ie u(i,j)=(j-1)*size_x+i end do end do do j=jsta,jend do i=is,ie u_tmp(i,j)=u(i,j) end do end do do k=0,nprocs-1 call MPI_Barrier(MPI_COMM_WORLD,ierr) if (k==rank) then print *, rank write (*,'(8i5)') u end if end do do k = 0, nprocs - 1 call MPI_BCAST(u_tmp(is,jjsta(k)), jjlen(k), MPI_Integer,k, MPI_COMM_WORLD, ierr) end do deallocate (jjsta, jjlen, jjreq) u(is:ie,js:je)=u_tmp(is:ie,js:je) do k=0,nprocs-1 call MPI_Barrier(MPI_COMM_WORLD,ierr) if (k==rank) then print *, rank write (*,'(8i5)') u end if end do call MPI_Finalize(ierr) contains subroutine para_range(n1, n2, nprocs, irank, ista, iend) ! block distribution integer n1 !The lowest value of the iteration variable (IN) integer n2 !The highest value of the iteration variable (IN) integer nprocs !The number of processes (IN) integer irank !The rank for which you want to know the range of iterations(IN) integer ista !The lowest value of the iteration variable that process irank executes (OUT) integer iend !The highest value of the iteration variable that process irank executes (OUT) integer iwork1,iwork2 iwork1 = (n2 - n1 + 1) / nprocs iwork2 = mod(n2 - n1 + 1, nprocs) ista = irank * iwork1 + n1 + min(irank, iwork2) iend = ista + iwork1 - 1 if (iwork2 > irank) iend = iend + 1 end subroutine para_range end program mpi_test2