title: MPI4PY - Why does my while loop only exit on some ranks?
body: <p>I have parallelised some codes to make frames for a movie. All the ranks exit the while loop except for the one creating the final frame, despite it reaching the end condition. Also I found that it only makes the final frame if I add a CW.Barrier() after the while loop. If that's not there, then it stalls on the second last frame.</p>
  
  <pre><code>rank = CW.Get_rank()
  size = CW.Get_size()
  
  rit = 0 #rank iterator. Its used to assign frames to make
  while len(frames) &gt; 0:
      if rank == rit:
          frame_val = frames.pop() #gets frame
          orit = 0
          while orit &lt; size:
              if orit != rit:
                  CW.send(frames, dest=orit, tag=1) #and then sends undated frame list to other ranks
              orit = orit + 1
  
      #other ranks recieve new list of frames.
      if rank != rit:
          frames = CW.recv(source=rit, tag=1)
  
  
      if rank == rit:
          #Creates frame
          print 'Created frame', frame_val, 'on rank', rank
  
      #iterates through ranks to distribute frames.
      rit = rit +1
      if rit == size:
          rit = 0
  
  CW.Barrier()
  print "completed making movie frames on rank", rank
  </code></pre>