!-------------------------------------------------- ! Send/Recv pages of matrix ! !-------------------------------------------------- Module Struc integer, parameter :: NROW = 8192, & Lblock = 16, & Nblocks= NROW/Lblock integer*4 :: iMask(Nblocks,Nblocks) ! Refinement Mask integer*4 :: rank,numprocs Contains SUBROUTINE SetMask !------------------------------------------------ use mpi Dimension nLevel (10) Character *70 Line Integer*4, ALLOCATABLE, DIMENSION(:,:,:) :: iMs !Integer*4 :: status integer*4 :: status(MPI_STATUS_SIZE) N3 = Nblocks**3 If(rank == 0)Then ALLOCATE(iMs(Nblocks,Nblocks,Nblocks)) DO MK3 = 1, Nblocks DO MK2 = 1, Nblocks DO MK1 = 1, Nblocks iMs (MK1, MK2,MK3) = MK1+MK3 ENDDO ENDDO ENDDO write(16,*) ' Initialized iMs: ',iMs (1,1,1),iMs (1,1,Nblocks) EndIf !CALL MPI_Bcast(iMs,N3,MPI_INTEGER,0,MPI_COMM_WORLD,ierr) ! k = rank+1 ! kk = (k-1)/Lblock+1 ! iMask = iMs(:,:,kk) If(rank == 0)Then Do k =2,256 !2,NROW kk = (k-1)/Lblock+1 write(16,*) ' Send: ',k,kk iMask = iMs(:,:,kk) CALL MPI_Send(iMask,Nblocks**2,MPI_INTEGER,k-1,1, & MPI_COMM_WORLD,ierr) !CALL MPI_Send(k,1,MPI_INTEGER,k-1,1, & ! MPI_COMM_WORLD,ierr) EndDo iMask = iMs(:,:,1) DEALLOCATE(iMs) Else write(16,*) ' Receive rank=',rank CALL MPI_Recv(iMask,Nblocks**2,MPI_INTEGER,0,1, & MPI_COMM_WORLD,status,ierr) !CALL MPI_Recv(jk,1,MPI_INTEGER,0,1, & ! MPI_COMM_WORLD,status,ierr) write(16,'(a,i4,a,8i5)') ' rank=',rank,' got iMask:',iMask(1,1),iMask(Nblocks,Nblocks) endIf !Do j=1,Nblocks ! write(16,'(32i3)')(iMask(i,j),i=1,Nblocks) !EndDO RETURN END SUBROUTINE SetMask ! end module STRUC !------------------------------------------- Program ReadandSpread use Struc use mpi character*80 File,Line CALL MPI_INIT(ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs,ierr) write(File,'(a,i4.4,a)') 'outFile.',rank,'.dat' open(16,file=File) write(16,*) ' My rank = ',rank Call SetMask CALL MPI_Finalize(ierr) end Program ReadandSpread