Community
cancel
Showing results for 
Search instead for 
Did you mean: 
diedro
Beginner
72 Views

mpi_type_vector three dimensional

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) 
ENDPROGRAM

In 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

 

0 Kudos
1 Reply
John_D_6
New Contributor I
72 Views

Dear Diedro,

I recommend to use the call MPI_TYPE_CREATE_SUBARRAY, it has a much clearer syntax to communicate parts of a multi-dimensional Fortran array.

Cheers,

John

Reply