我已经并行化了一些代码来制作电影的帧。所有排名都退出 while 循环,除了创建最后一帧的那一个,尽管它达到了结束条件。我还发现,如果我在 while 循环之后添加 CW.Barrier(),它只会生成最后一帧。如果那不存在,那么它会停在倒数第二帧。
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