MPI4Py Scatter sendbuf 参数类型?
我在使用MPI4Py这个Python模块的Scatter函数时遇到了问题。我的想法是,我应该可以把一个单独的列表传给它作为发送缓冲区。但是,当我这样做,或者添加其他两个参数接收缓冲区和根节点时,我总是收到一个错误信息。
File "code/step3.py", line 682, in subbox_grid
i = mpi_communicator.Scatter(station_range, station_data)
File "Comm.pyx", line 427, in mpi4py.MPI.Comm.Scatter (src/
mpi4py_MPI.c:44993)
File "message.pxi", line 321, in mpi4py.MPI._p_msg_cco.for_scatter
(src/mpi4py_MPI.c:14497)
File "message.pxi", line 232, in mpi4py.MPI._p_msg_cco.for_cco_send
(src/mpi4py_MPI.c:13630)
File "message.pxi", line 36, in mpi4py.MPI.message_simple (src/
mpi4py_MPI.c:11904)
ValueError: message: expecting 2 or 3 items
这里是相关的代码片段,从682行上方开始。
for station in stations
#snip--do some stuff with station
station_data = []
station_range = range(1,len(station))
mpi_communicator = MPI.COMM_WORLD
i = mpi_communicator.Scatter(station_range, nsm)
#snip--do some stuff with station[i]
nsm = combine(avg, wt, dnew, nf1, nl1, wti[i], wtm, station[i].id)
station_data = mpi_communicator.Gather(station_range, nsm)
我尝试了多种方式来初始化station_range,但我可能没有正确理解Scatter函数的参数类型。
有没有Python/MPI方面的高手能帮我解释一下这个问题?
1 个回答
6
如果你想移动原始数据块(就像使用 Gather
一样),你需要提供一个三元组 [buffer, size, type]
。可以查看示例来了解具体怎么做。如果你想发送 Python 对象,建议使用更高级的接口,调用 gather
(注意是小写),这个方法内部会使用 pickle
来处理。