0
#mpiexec -n 3 python pass_dict.py
from mpi4py import MPI
import psycopg2
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
tax_dict={}
if rank == 0:
tax_files=['2008','2009','2011','2012','2013','2014','2015']
file_dir='/zhome/nah316/taxonomy/'
for tax_file in tax_files:
filename=file_dir + tax_file+'.csv'
with open(filename,'r') as f:
temp={}
for line in f:
temp_list=[]
splitted_line = line.split()
tag=splitted_line[1]
temp_list.append(tag)
temp[splitted_line[1]] = temp_list
tax_dict[tax_file]=temp
else:
tax_dict=None
comm.bcast(tax_dict, root = 0)
print '-' * 20, rank , '-'* 30
print tax_dict['2015']['InvestmentSoldNotYetPurchasedRestrictedCost']
下面是我試圖構建字典字典的代碼,並將它在通信器上對其他2個核心進行了播客。當我跑它,我得到的錯誤:mpi4py傳遞字典對象
-------------------- 2 ------------------------------
Traceback (most recent call last):
File "pass_dict.py", line 33, in <module>
print tax_dict['2015']['InvestmentSoldNotYetPurchasedRestrictedCost']
TypeError: 'NoneType' object has no attribute '__getitem__'
-------------------- 1 ------------------------------
Traceback (most recent call last):
File "pass_dict.py", line 33, in <module>
print tax_dict['2015']['InvestmentSoldNotYetPurchasedRestrictedCost']
TypeError: 'NoneType' object has no attribute '__getitem__'
-------------------- 0 ------------------------------
['InvestmentSoldNotYetPurchasedRestrictedCost']
它在我看來,這得到了傳遞到根以外的核心字典已經失去了一些功能的字典。爲什麼是這樣?我應該如何解決這個問題,並在通向根節點的路徑上進行傳遞?
在此先感謝!
解決了這個問題!謝謝! –