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