【问题标题】:mpi4py Bcast() deadlockmpi4py Bcast() 死锁
【发布时间】:2018-04-16 18:51:04
【问题描述】:

我正在尝试使用 Bcast() 在每一步广播一个递归更改的 numpy 数组。我的代码如下所示:

gn_forecast =np.empty((4*p,1), dtype=np.float64)
if (rank == 0):
    gn_forecast = np.zeros((4*p,1), dtype=np.float64)

if (rank ==0):
    count = 0
    for l in range(p):
        for k in range(4):
            gn_forecast[count] = (history[k][len(history[k])-l-1])
            count+=1

comm.Bcast(gn_forecast,root=0)

当我使用 Bcast() 时。我可能遇到了死锁,因为我没有错误并且脚本没有完成。 谁能明白为什么?

【问题讨论】:

标签: python python-3.x parallel-processing mpi4py


【解决方案1】:

您没有正确使用Bcast。作为第一个参数,您应该提供一个列表,其中 numpy 数组作为第一个元素 (gn_forecast),并将 MPI 类型作为第二个元素。在你的情况下,它是MPI.DOUBLE

我已经简化了你的代码的串行部分,以下是我这边的工作:

from __future__ import print_function
import numpy as np
from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.rank
p=1

gn_forecast =np.empty((4*p,1), dtype=np.float64)
if (rank == 0):
    gn_forecast = np.ones((4*p,1), dtype=np.float64)*5.0

print("Rank: ", rank, ". gn_forecast is:\n", gn_forecast)
comm.Bcast( [gn_forecast, MPI.DOUBLE] ,root=0)
print("Rank: ", rank, ". gn_forecast is:\n", gn_forecast)

【讨论】:

    猜你喜欢
    • 2020-03-11
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 2014-06-08
    • 2013-11-30
    • 2013-12-25
    • 2015-01-29
    相关资源
    最近更新 更多