Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

MPI_Sendrecv setting rank to zero.

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
Highlighted
Beginner

Figured it out. mpi_status

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