Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

MPI_Sendrecv setting rank to zero.

Navdeep_Rana
Beginner
561 Views

I am trying to use mpi_sendrecv, but it sets my process ranks to 0.

The c version works fine. Can anyone help?

Here's the code.

program mpi_bug
  use mpi
  implicit none
  integer :: n,i
  integer :: mpi_rank,mpi_procs,mpi_status_flag,mpi_error_flag
  integer :: src,dest,dsize

  integer,allocatable,dimension(:) :: p
  call mpi_init(mpi_status_flag)
  call mpi_comm_rank(mpi_comm_world, mpi_rank,mpi_status_flag)
  call mpi_comm_size(mpi_comm_world, mpi_procs, mpi_status_flag)

  n = 2
  allocate(p(1:n+1))
  p(:) = 0

  do i=2,n+1
    p(i) = mpi_rank+1
  enddo
  !! After this p is
  !! rank =0 : 0 1 1
  !! rank =1 : 0 2 2

  dsize = 1

  ! Send Second Last element to next processor (periodic) which takes and stores it as
  ! 1st array element.
  ! Output should be
  
  !! rank =0 : 2 1 1
  !! rank =1 : 1 2 2

  if (mpi_rank == mpi_procs - 1) then
    dest = 0
  else
    dest = mpi_rank+1
  endif
  if (mpi_rank == 0) then
    src = mpi_procs - 1
  else
    src = mpi_rank - 1
  endif

  call MPI_SENDRECV(p(n+1),dsize,MPI_INTEGER,dest,0,&
    p(1),dsize,MPI_INTEGER,src,0,MPI_COMM_WORLD,mpi_status_flag,mpi_error_flag)

  write(*,*) p

  write(*, *) "AFTER :" , mpi_rank

  call mpi_finalize(mpi_status_flag)
end program mpi_bug

 

0 Kudos
1 Reply
Navdeep_Rana
Beginner
561 Views

Figured it out. mpi_status_flag is not an integer.

integer :: mpi_status_flag (mpi_status_size)
call mpi_init(mpi_error_flag)
call mpi_comm_rank(mpi_comm_world, mpi_rank,mpi_error_flag)
call mpi_comm_size(mpi_comm_world, mpi_procs, mpi_error_flag)

 

 

0 Kudos
Reply