我想使用MPI(mpi4.py)(消息传递接口)拆分字典的迭代
比如说,
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
tmp_list = []
for key, value in some_dict.items():
tmp_values = some_function(key,value)
tmp_list.append(tmp_values)
这里有一些简单的代码。
如何为迭代编写MPI代码
Tags:
您首先需要将dict转换为一个列表,然后将该列表划分为您将要使用的多个进程。这是必要的,以便
comm.scatter
可以跨所有进程发送部分数据。然后可以使用comm.gather
收集最终结果script.py
使用
chmod
使其可执行chmod +x script.py
然后跑
mpiexec -n 4 script.py
-n是要运行的进程数
注意:我使用的是ubuntu 16.04、python 3.7.10和mpi4py==3.0.3
相关问题 更多 >
编程相关推荐