Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.

MPI_TYPE_CREATE_STRUCT error 174

diedro
Beginner
921 Views

Dear all,

this is becoming a nightmare. I have the following program, where i create MPI_TYPE_CREATE_STRUCT and then I try to send it to other processor. It crushes every-time and do not know why.

Could someone please help me?

 

PROGRAM PROVA_STRUCT
IMPLICIT NONE
INCLUDE 'mpif.h'
!
TYPE tMPI
    INTEGER :: myrank, nCPU, iErr, status
    INTEGER :: AUTO_REAL
    INTEGER :: iStart, iEnd, jStart, jEnd 
    INTEGER :: imax, jmax
    INTEGER :: npt
    INTEGER :: nmcx,nmcy
    REAL    :: x1L,x2L,y1L,y2L
    REAL    :: err 
    INTEGER, ALLOCATABLE :: mycoords(:), info(:)
END TYPE tMPI
!
type particle
 integer                 :: rx
 real                    :: QQ
end type particle
!
TYPE(tMPI)           :: MPI
INTEGER              :: COMM_CART
INTEGER              :: MPI_PARTICLE_TYPE
INTEGER,ALLOCATABLE  :: DIMS(:)
LOGICAL,ALLOCATABLE  :: PERIODS(:)
INTEGER              :: RCPU,LCPU,BCPU,TCPU,RTCPU,RBCPU,LTCPU,LBCPU

INTEGER              :: source
INTEGER              :: ndims
INTEGER              :: nstruct
INTEGER              :: x_thread,y_thread

INTEGER,ALLOCATABLE  :: TYPES(:)
INTEGER,ALLOCATABLE  :: LENGTHS(:)
INTEGER,ALLOCATABLE  :: DISPLACEMENTS(:)

INTEGER        :: npt,ip
type(particle) :: dummy                   ! Used for calculation of displacement
TYPE(particle),ALLOCATABLE :: P_SEND(:),P_RECV(:)



   CALL MPI_INIT(MPI%iErr)
   CALL MPI_COMM_RANK(MPI_COMM_WORLD, MPI%myrank, MPI%iErr)
   CALL MPI_COMM_SIZE(MPI_COMM_WORLD, MPI%nCPU,   MPI%iErr)
   !
   ndims=2
   !
   x_thread = MPI%nCPU/ndims
   y_thread = x_thread
   !
   ALLOCATE ( dims(ndims), periods(ndims), MPI%mycoords(ndims) )
   dims = [x_thread, y_thread]
   periods = .FALSE.
   CALL MPI_CART_CREATE (MPI_COMM_WORLD,ndims,dims,periods,.TRUE.,COMM_CART,MPI%iErr)
   CALL MPI_COMM_RANK(COMM_CART,MPI%myrank,MPI%iErr)

   !Find neighbors
  CALL MPI_CART_SHIFT(COMM_CART,0,1,source,RCPU,MPI%iErr)  ! x-dir, right
  CALL MPI_CART_SHIFT(COMM_CART,0,-1,source,LCPU,MPI%iErr) ! x-dir, left
  CALL MPI_CART_SHIFT(COMM_CART,1,1,source,TCPU,MPI%iErr)  ! y-dir, top
  CALL MPI_CART_SHIFT(COMM_CART,1,-1,source,BCPU,MPI%iErr) ! y-dir, bottom
   
   
   nstruct=2
   ALLOCATE(TYPES(nstruct))
   ALLOCATE(LENGTHS(nstruct))
   ALLOCATE(DISPLACEMENTS(nstruct))
   !
   TYPES(1)=MPI_INTEGER
   TYPES(2)=MPI_DOUBLE_PRECISION
   !
   LENGTHS(1)=1
   LENGTHS(2)=1
   ! 
   DISPLACEMENTS(1)=0
   DISPLACEMENTS(2)=sizeof(dummy%rx)
   CALL MPI_TYPE_CREATE_STRUCT(nstruct,lengths,displacements,types,mpi_particle_type,MPI%iErr)
   CALL MPI_TYPE_COMMIT(mpi_particle_type,MPI%iErr)
!    
   NPT=10
   ALLOCATE(P_SEND(NPT))
   ALLOCATE(P_RECV(NPT))
   DO ip=1,NPT
      P_SEND(ip)%rx=1
      P_SEND(ip)%QQ=11.
      P_RECV(ip)%rx=0
      P_RECV(ip)%QQ=0.
   ENDDO
   
   
   CALL MPI_BARRIER(MPI_COMM_WORLD,MPI%iErr)
   CALL MPI_Sendrecv(P_SEND(:),10,MPI_PARTICLE_TYPE,BCPU,201,&
                     P_RECV(:),10,MPI_PARTICLE_TYPE,TCPU,201,MPI_COMM_WORLD,MPI_STATUS_IGNORE,MPI%iErr)
   
   CALL MPI_FINALIZE(MPI%iErr)

ENDPROGRAM

I think that this one is a very simple program, that can be useful for me to understand where I do not understand.

Thanks a lot

0 Kudos
0 Replies
Reply