问题描述
我有以下两部分代码,第一部分是使用多处理的代码,第二部分是使用mpi4py。
多孔加工一个
def simple(data): #(np.arrray) # its a function from other module
result = do something with the data
return result #(np.arrray)
def lesssimple(data,num):
num_cores = num
inputs = tqdm(x)
processed_list = Parallel(n_jobs=num_cores)(delayed(simple)(i,num) for i in inputs)
return processed_list
Mpi4py 一个
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
if rank == 0:
data = np.array_split(dat,size)
else:
data = None
recvbuf = comm.scatter(data,root=0)
result = []
for item in recvbuf:
result.append(somefunction(item))
newData = comm.gather(result,root=0)
if rank == 0:
with open('result.data','wb') as filehandle:
pickle.dump(newData,filehandle)
我的问题是,如果我想在 Mpi4py 指定的每个节点中进行多处理作业,可以像下面那样简单地组合它们吗? (对于列表中的每个数据,计算是独立的,不需要通信)。
#all the others the same with mpi4py
result = []
for item in recvbuf:
result.append(lesssimple(data,num)) ### plugging the multiprocessing function into this part
#all the others the same with mpi4py
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)