fortran - Why this MPI_SENDRECV is deadlock? -


this first post. thank in advance kind help. short code testing mpi_sendrecv,which did not understand. deadlock can tell me why?

 program sendrecv   include "mpif.h"   integer ibuf(20)   call mpi_init(ierr)   call mpi_comm_size(mpi_comm_world, nprocs, ierr)   call mpi_comm_rank(mpi_comm_world, myrank, ierr)   a=1   b=2   if (myid == 0)      call mpi_sendrecv(a,1,mpi_real,1,0,  .                     b,1,mpi_real,1,0,  .                     mpi_comm_world, status,ierr)   elseif (myid == 1)      call mpi_sendrecv(b,1,mpi_real,0,0,  .                     a,1,mpi_real,0,0,  .                     mpi_comm_world,status,ierr)   end if   if (myid.eq.0)      write(*,*)   endif   if (myid.eq.1)      write(*,*) b   endif   call mpi_finalize(ierr)   end 

as pointed out @steveblackwell, you're using myid instead of myrank. if use:

call mpi_comm_rank(mpi_comm_world, myid, ierr)  

instead you'll halfway there. deadlock arises here because both processors (probably) have myid = 0 (note, behavior compiler dependent -- other compilers might set strange number , program appear work, no messages passed).

your second problem status implicitly declared real variable, mpi expecting integer array size mpi_status_size. have sorts of effects -- segfault, or worse, strange memory error since mpi writing buffer shouldn't. (alternatively, use mpi_status_ignore since you're not doing status anyway).

as pointed out @highperformancemark, best practice explicitly type in program , use implicit none avoid these types of problems. in other words, should have reason if subroutine/module/function/main program don't have implicit none in declaration.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -