!********************************************************************** ! Derived datatypes, Send the last from 0 and store it as the first ! row in processor 1 ! !**************************************************************************** program datatypes include 'mpif.h' integer, parameter :: DP=kind(0.0D0) real(kind=DP),dimension(:,:),allocatable :: A integer :: n, myid, numprocs,nx,ny,row,col,count,blocklen,stride integer :: status,ierr call MPI_INIT( ierr ) call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr ) call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr ) nx=100; ny=150 allocate(A(nx,ny)); do col=1,ny do row=1,nx A(row,col)=col+(rank+1)*1000.0; end do end do ! Notice, in Fortran data is stored column-wise, ! sending a row is then a problem count=ny; blocklen=1; stride=nx; call MPI_Type_vector(count,blocklen,stride,MPI_DOUBLE_PRECISION,newtype,ierr); call MPI_Type_commit(newtype,ierr); !* Send last row, notice the message length = 1 ! *! if (myid == 0) then call MPI_Send(A(nx,1), 1, newtype, 1, 111, MPI_COMM_WORLD,ierr) elseif (myid==1) then call MPI_Recv(A(1,1), 1, newtype, 0, 111, MPI_COMM_WORLD, status, ierr); do col=1,ny write(*,*) A(1,col) end do end if deallocate(A) call MPI_Type_free(newtype,ierr); call MPI_FINALIZE(ierr) end program datatypes