<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I see that you use an in Intel® MPI Library</title>
    <link>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009087#M3875</link>
    <description>&lt;P&gt;I see that you use an uninitialized value for&amp;nbsp; msgtag . It is input for MPI_SEND and MPI_SEND.&lt;/P&gt;

&lt;P&gt;Thus the actual value for&amp;nbsp; msgtag&amp;nbsp; is random, and might be different for the 2 code-variants. What happens if it is a NaN&amp;nbsp;?&lt;/P&gt;

&lt;P&gt;So make sure that you do not use uninitialized values.&lt;/P&gt;

&lt;P&gt;By the way,&amp;nbsp;I would not use an variable named&amp;nbsp;&amp;nbsp; size&amp;nbsp; , because&amp;nbsp; &amp;nbsp;size&amp;nbsp; is also &amp;nbsp;an intrinsic fct in Fortran.&lt;/P&gt;

&lt;P&gt;Greetings Michael R.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Oct 2014 07:55:51 GMT</pubDate>
    <dc:creator>Michael_R_2</dc:creator>
    <dc:date>2014-10-01T07:55:51Z</dc:date>
    <item>
      <title>simple MPI code generating deadlock</title>
      <link>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009086#M3874</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;

&lt;P&gt;I hope this is the appropriate forum for this question. I have recently started learning MPI, and can't seem to figure out why the following codes generating deadlock which occurs is subroutine try_comm. I compiled and ran as follows&lt;/P&gt;

&lt;P&gt;mpiifort global.f90 try.f90 new.f90 -o new.out&lt;/P&gt;

&lt;P&gt;mpirun -n 2 ./new.out&lt;/P&gt;

&lt;P&gt;my output:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;hello from rank 0 2

entering 0 0

waiting for receive from rank 1  1

entering 1 0

after send

finished 1 0&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;module global

  implicit none
  integer :: size,rank
  integer,allocatable :: p2n(:),n2p(:)
end module global&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;module try
  use mpi
  use global
  implicit none
contains
  
  subroutine try_comm(loop,n0)
    implicit none
    integer :: n0,loop
    integer :: ierr,msgtag
    integer :: n0temp
    integer :: status(MPI_STATUS_SIZE)
    

    call mpi_barrier(MPI_COMM_WORLD,ierr)

    print*,'entering',rank,loop
    if(rank.ne.0)then
       call mpi_send(n0,1,mpi_int,0,msgtag,MPI_COMM_WORLD,ierr)
       print*,'after send'
    endif
    
    if(rank.eq.0)then
       do loop = 1,size-1
          print*,'waiting for receive from rank',loop,size-1
          call mpi_recv(n0temp,1,mpi_int,loop,msgtag,MPI_COMM_WORLD,status,ierr)
          n0 = n0temp
          print*,'received 0:',n0
       enddo
       
    endif

    print*,'finished',rank,loop

    call mpi_barrier(MPI_COMM_WORLD,ierr)
    
  end subroutine try_comm
  
end module try
&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;program new
  use mpi
  use global
  use try
  implicit none
  integer :: n0
  integer :: ierr,msgtag
  integer :: loop
  integer :: n0temp
  integer :: status(MPI_STATUS_SIZE)
  
  call mpi_init(ierr)
  call mpi_comm_size(MPI_COMM_WORLD,size,ierr)
  call mpi_comm_rank(MPI_COMM_WORLD,rank,ierr)
  
  
  if(rank.eq.0)then
     print*,'hello from rank',rank,size
     allocate(p2n(0:size-1),n2p(0:size-1))
  endif
  
  n0 = rank*10

 
  do loop = 1,20
     call try_comm(loop,n0)
  enddo

  call mpi_finalize(ierr)

  stop
end program new
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;However, if I change new.f90 to the following where now the subroutine try_comm is included in the do loop as follows, I do not get deadlock.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program new
  use mpi
  use global
  use try
  implicit none
  integer :: n0
  integer :: ierr,msgtag
  integer :: loop,loopa
  integer :: n0temp
  integer :: status(MPI_STATUS_SIZE)
  
  call mpi_init(ierr)
  call mpi_comm_size(MPI_COMM_WORLD,size,ierr)
  call mpi_comm_rank(MPI_COMM_WORLD,rank,ierr)
  
  
  if(rank.eq.0)then
     print*,'hello from rank',rank,size
     allocate(p2n(0:size-1),n2p(0:size-1))
  endif
  
  n0 = rank*10


  do loopa = 1,20
     !call try_comm(loop,n0)

     call mpi_barrier(MPI_COMM_WORLD,ierr)
     
     print*,'entering',rank,loopa
     if(rank.ne.0)then
        call mpi_send(n0,1,mpi_int,0,msgtag,MPI_COMM_WORLD,ierr)
        print*,'after send'
     endif
     
     if(rank.eq.0)then
        do loop = 1,size-1
           print*,'waiting for receive from rank',loop,size-1
           call mpi_recv(n0temp,1,mpi_int,loop,msgtag,MPI_COMM_WORLD,status,ierr)           
           n0 = n0temp
           print*,'received 0:',n0
        enddo
        
     endif
     
     print*,'finished',rank,loopa
     call mpi_barrier(MPI_COMM_WORLD,ierr)

     
  enddo


  call mpi_finalize(ierr)

  stop
end program new
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 18:36:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009086#M3874</guid>
      <dc:creator>conor_p_</dc:creator>
      <dc:date>2014-09-30T18:36:16Z</dc:date>
    </item>
    <item>
      <title>I see that you use an</title>
      <link>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009087#M3875</link>
      <description>&lt;P&gt;I see that you use an uninitialized value for&amp;nbsp; msgtag . It is input for MPI_SEND and MPI_SEND.&lt;/P&gt;

&lt;P&gt;Thus the actual value for&amp;nbsp; msgtag&amp;nbsp; is random, and might be different for the 2 code-variants. What happens if it is a NaN&amp;nbsp;?&lt;/P&gt;

&lt;P&gt;So make sure that you do not use uninitialized values.&lt;/P&gt;

&lt;P&gt;By the way,&amp;nbsp;I would not use an variable named&amp;nbsp;&amp;nbsp; size&amp;nbsp; , because&amp;nbsp; &amp;nbsp;size&amp;nbsp; is also &amp;nbsp;an intrinsic fct in Fortran.&lt;/P&gt;

&lt;P&gt;Greetings Michael R.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2014 07:55:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009087#M3875</guid>
      <dc:creator>Michael_R_2</dc:creator>
      <dc:date>2014-10-01T07:55:51Z</dc:date>
    </item>
    <item>
      <title>dear Conor,</title>
      <link>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009088#M3876</link>
      <description>&lt;P&gt;dear Conor,&lt;/P&gt;

&lt;P&gt;I suggest to use only two CPU, one to send and one to receive. It is easier to&amp;nbsp;catch the error.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Diego&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Oct 2014 08:41:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009088#M3876</guid>
      <dc:creator>diedro</dc:creator>
      <dc:date>2014-10-06T08:41:38Z</dc:date>
    </item>
    <item>
      <title>thanks guys! that first</title>
      <link>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009089#M3877</link>
      <description>&lt;P&gt;thanks guys! that first response actually answered the question for me. For some reason my understanding after reading a couple MPI examples was that MPI handled msgtag behind the scenes, but evidently that is very,very wrong. thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Oct 2014 03:14:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-MPI-Library/simple-MPI-code-generating-deadlock/m-p/1009089#M3877</guid>
      <dc:creator>conor_p_</dc:creator>
      <dc:date>2014-10-08T03:14:11Z</dc:date>
    </item>
  </channel>
</rss>

