2016-01-08 50 views
0

我已經並行化了一些代碼來製作電影的幀。儘管達到最終條件,所有的等級都會退出while循環,除了創建最終幀的那個等級。我還發現,如果我在while循環之後添加一個CW.Barrier(),它纔會生成最終幀。如果那不在那裏,那麼它在第二個最後一幀停止。MPI4PY - 爲什麼我的while循環只能退出某些行列?

rank = CW.Get_rank() 
size = CW.Get_size() 

rit = 0 #rank iterator. Its used to assign frames to make 
while len(frames) > 0: 
    if rank == rit: 
     frame_val = frames.pop() #gets frame 
     orit = 0 
     while orit < 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 

回答

0

皮皮,所以我沒有提供足夠的信息在我的問題。在

if rank == rit: #Creates frame print 'Created frame', frame_val, 'on rank', rank

實際上,它看起來更像是:

if rank == rit: CW.Barrier() #Creates frame print 'Created frame', frame_val, 'on rank', rank

因爲一些行列,同時外觀已經退出,並不是所有隊伍在達到這個CW.Barrier()函數最後一幀。這個障礙在這個地方實際上並不是必需的,所以它是固定的!