Dear all,
I have a three dimensional array AA(:,:,:) and I would like to sent it, or at least part of it from one CPU to another.
The idea is to combine MPI_TYPE_VECTOR. This is my program. I do not understand it, sometimes it works and some time not.
What do you think?
program vector
USE mpi
IMPLICIT NONE
integer SIZE_
parameter(SIZE_=4)
integer numtasks, rank, source, dest, tag, i, ierr
real*4 AA(SIZE_,5,4), BB(SIZE_,5,4)
integer stat(MPI_STATUS_SIZE), rowtype,colrowtype
!Fortran stores this array in column major order
AA=0.
AA(1,1,1)= 1.0
AA(1,1,2)= 4.0
AA(1,1,3)= 10.0
AA(1,1,4)= 33.0
AA(2,1,1)= 10.0
AA(2,1,2)= 40.0
AA(2,1,3)= 100.0
AA(2,1,4)= 330.0
CALL MPI_INIT(ierr)
CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD, numtasks, ierr)
CALL MPI_TYPE_VECTOR(5, 5, 5, MPI_REAL, rowtype, ierr)
CALL MPI_TYPE_COMMIT(rowtype, ierr)
CALL MPI_TYPE_VECTOR(4, 4, 4, rowtype, colrowtype, ierr)
CALL MPI_TYPE_COMMIT(colrowtype, ierr)
CALL MPI_BARRIER(MPI_COMM_WORLD, ierr)
IF(rank==0)THEN
i=1
call MPI_SEND(AA(1,1,1), 2, colrowtype, 1, 300, MPI_COMM_WORLD, ierr)
ENDIF
IF(rank==1)THEN
source = 0
call MPI_RECV(BB(1,1,1), 2, colrowtype, 0, 300, MPI_COMM_WORLD, stat, ierr)
!
WRITE(*,*) ' b= ', BB(1,1,:)
!
WRITE(*,*) ' b= ', BB(1,1,:)
ENDIF
call MPI_FINALIZE(ierr)
ENDPROGRAMIn this case the program does not work. If a use
real*4 AA(SIZE_,4,4), BB(SIZE_,4,4)
and
CALL MPI_TYPE_VECTOR(4, 4, 4, MPI_REAL, rowtype, ierr) CALL MPI_TYPE_COMMIT(rowtype, ierr) CALL MPI_TYPE_VECTOR(4, 4, 4, rowtype, colrowtype, ierr) CALL MPI_TYPE_COMMIT(colrowtype, ierr)
it works. I believe that this is due to how a matrix is stored in Fortran.
Someone could explain me where I am wrong?
Thanks Thanks a lot