1

我在根進程中有一個計數器對象,我想將它分散到組中的所有進程,但分散函數給出了錯誤(我也嘗試過使用Scatter()但沒有運氣) 。我正在使用mpi4py進行並行處理。組中的所有進程的散點計數器對象

Traceback (most recent call last): 
File "tsetscatter.py", line 13, in <module> 
total_counter = comm.scatter(total_counter, root=0) 
File "MPI/Comm.pyx", line 1286, in mpi4py.MPI.Comm.scatter 
(src/mpi4py.MPI.c:109079) 
File "MPI/msgpickle.pxi", line 707, in mpi4py.MPI.PyMPI_scatter 
(src/mpi4py.MPI.c:48114) 
File "MPI/msgpickle.pxi", line 161, in mpi4py.MPI.Pickle.dumpv 
(src/mpi4py.MPI.c:41605) 
ValueError: expecting 8 items, got 5 

的源代碼是:

from mpi4py import MPI 
from collections import Counter 

if __name__ == "__main__": 
comm = MPI.COMM_WORLD 
rank = comm.Get_rank() 
size = comm.Get_size() 
total_counter = [] 
if rank == 0: 
    lst = [('key1', 2), ('key2', 6), ('key3', 9), ('key4', 4), ('key5', 1)] 
    total_counter = Counter(dict(lst)) 
print total_counter 
total_counter = comm.scatter(total_counter, root=0) 
print total_counter 

任何有關如何可以做到這一點是高度讚賞幫助。

回答

0

我能夠通過創建數據塊散射它(組塊的數目=無的過程。)

if rank == 0: 
lst = [('key1', 2), ('key2', 6), ('key3', 9), ('key4', 4), ('key5', 1)] 
total_counter = Counter(dict(lst)) 
chunks = [[]for _ in range(size)] 
for i, chunk in enumerate(total_counter): 
    chunks[i % size].append({chunk: total_counter.get(chunk)}) 
else: 
total_counter = None 
chunks = None 
total_counter = comm.scatter(chunks, root=0) 
print rank, ": ", total_counter 

它正在工作,目前預計。