Dear all, thanks thank a lot, I am learning a lot. I have written a simple program that send vectors of integers from a CPU to another.
The program is written (at least for now) for 4 CPU. The program is quite simple: Each CPU knows how many data has to send to the other CPUs. This info is than send to the other CPUS. In this way each CPU knows how may data has to receive from other CPUs. This part of the program works. The problem is in the second part. In the second part, each processor sends a vector of integer to the other processor. The size is given and each CPU knows the size of the incoming vector form the first part of the program. In this second part the program fails and I do not know why. In the attachment you can find the program. Could you please help me. Problably I didn't understand properly the ISEND and IRECV subroutine. Thanks again Diego
MODULE MOD_PRECISION integer, parameter :: dp = selected_real_kind(p=16) ENDMODULE MOD_PRECISION PROGRAM TEST USE MOD_PRECISION USE MPI IMPLICIT NONE ! INTEGER :: iCPU,icount,iTag,ip,sendcount,sendrecv,i ! TYPE tMPI INTEGER :: myrank, nCPU, iErr, status END TYPE tMPI ! INTEGER, ALLOCATABLE,DIMENSION(:) :: Ndata2send INTEGER, ALLOCATABLE,DIMENSION(:) :: Ndata2recv INTEGER, ALLOCATABLE,DIMENSION(:) :: DATASEND INTEGER, ALLOCATABLE,DIMENSION(:) :: DATARECV ! INTEGER :: send_request ( 3) INTEGER :: recv_request ( 3) INTEGER :: send_status_list (MPI_STATUS_SIZE,3) INTEGER :: recv_status_list (MPI_STATUS_SIZE,3) ! TYPE(tMPI) :: MPIdata CALL MPI_INIT(MPIdata%iErr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, MPIdata%myrank, MPIdata%iErr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, MPIdata%nCPU, MPIdata%iErr) ! ALLOCATE(Ndata2send(0:MPIdata%nCPU-1)) ALLOCATE(Ndata2recv(0:MPIdata%nCPU-1)) ! Ndata2send=0 Ndata2recv=0 ! IF(MPIdata%myrank==0)THEN Ndata2send(0)=0 Ndata2send(1)=10 Ndata2send(2)=10 Ndata2send(3)=16 ENDIF IF(MPIdata%myrank==1)THEN Ndata2send(0)=13 Ndata2send(1)=0 Ndata2send(2)=16 Ndata2send(3)=16 ENDIF IF(MPIdata%myrank==2)THEN Ndata2send(0)=13 Ndata2send(1)=16 Ndata2send(2)=0 Ndata2send(3)=16 ENDIF IF(MPIdata%myrank==3)THEN Ndata2send(0)=16 Ndata2send(1)=16 Ndata2send(2)=16 Ndata2send(3)=0 ENDIF ! CALL MPI_BARRIER(MPI_COMM_WORLD, MPIdata%iErr) icount=1 DO iCPU=0,MPIdata%nCPU-1 IF(iCPU.NE.MPIdata%myrank)THEN iTag=iCPU CALL MPI_ISEND(Ndata2send(iCPU),1,MPI_INTEGER,iCPU,iTag,MPI_COMM_WORLD,send_request(icount),MPIdata%iErr) icount=icount+1 ENDIF ENDDO ! icount=1 DO iCPU=0,MPIdata%nCPU-1 IF(iCPU.NE.MPIdata%myrank)THEN iTag=MPIdata%myrank CALL MPI_IRECV(Ndata2recv(iCPU),1,MPI_INTEGER,iCPU,iTag,MPI_COMM_WORLD,recv_request(icount),MPIdata%iErr) icount=icount+1 ENDIF ENDDO ! CALL MPI_WAITALL(MPIdata%nCPU-1,send_request,send_status_list,MPIdata%iErr) CALL MPI_WAITALL(MPIdata%nCPU-1,recv_request,recv_status_list,MPIdata%iErr) ! !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ! sendcount=1 DO iCPU=0,MPIdata%nCPU-1 IF(MPIdata%myrank.NE.iCPU)THEN ! ALLOCATE(DATASEND(Ndata2send(iCPU))) ! DO ip=1,Ndata2send(iCPU) DATASEND(ip) = ip ENDDO ! iTag=iCPU CALL MPI_ISEND(DATASEND(:),Ndata2send(iCPU),MPI_INTEGER,iCPU,iTag,MPI_COMM_WORLD,send_request(icount),MPIdata%iErr) sendcount=sendcount+1 DEALLOCATE(DATASEND) ! ENDIF ENDDO ! ! CALL MPI_BARRIER(MPI_COMM_WORLD, MPIdata%iErr) ! ! sendrecv=1 DO iCPU=0,MPIdata%nCPU-1 ! ALLOCATE(DATARECV(Ndata2send(iCPU))) ! IF(MPIdata%myrank.NE.iCPU)THEN iTag=MPIdata%myrank CALL MPI_IRECV(DATARECV,Ndata2recv(iCPU),MPI_INTEGER,iCPU,iTag,MPI_COMM_WORLD,recv_request(sendrecv),MPIdata%iErr) sendrecv=sendrecv+1 ENDIF DO i=1,Ndata2recv(iCPU) WRITE(*,*) DATARECV(i) ENDDO ! DEALLOCATE(DATARECV) ! ENDDO CALL MPI_WAITALL(MPIdata%nCPU-1,send_request,send_status_list,MPIdata%iErr) CALL MPI_WAITALL(MPIdata%nCPU-1,recv_request,recv_status_list,MPIdata%iErr) CALL MPI_Finalize(MPIdata%iErr) ENDPROGRAM