! ! On src: m(10,10) ! send section m(2:6,4:9) ! ! On dest m(12,8) ! recv section m(7:11,2:7) program array_sect implicit none include "mpif.h" integer, dimension(:,:), allocatable :: m integer :: mx, my, nx, ny integer ierror, rank, size integer, parameter :: src = 1, dest = 0 integer section, status(MPI_STATUS_SIZE) integer i,j call MPI_Init(ierror) call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror) call MPI_Comm_size(MPI_COMM_WORLD, size, ierror) if (rank==src) then mx = 10; my = 10 allocate(m(mx,my)) write(*,'("Source array:")') do j = 1,10 do i = 1,10 m(i,j) = (i-1)*10 + j-1 enddo write(*,'(10i4)') m(:,j) enddo nx = 6-2+1; ny = 9-4+1; ! m(2:6,4:9) else mx = 12; my = 8 allocate(m(mx,my)) m = 0 nx = 11-7+1; ny = 7-2+1; ! m(7:11,2:7) endif call MPI_Type_Vector(ny, nx, mx, MPI_INTEGER, section, ierror) call MPI_Type_Commit(section, ierror) if (rank==src) then call MPI_Send( m(2,4), 1, section, dest, 7, MPI_COMM_WORLD, ierror) else call MPI_Recv( m(7,2), 1, section, src, 7, & MPI_COMM_WORLD, status, ierror) write(*,'("Target array:")') do j = 1,7 write(*,'(12i4)') m(:,j) enddo end if call MPI_Finalize(ierror) stop end program array_sect