繁体   English   中英

mpi4py Bcast()死锁

[英]mpi4py Bcast() deadlock

我试图使用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()时。 我遇到了死锁,可能是因为我没有错误并且脚本没有完成。 谁能看到原因?

您没有正确使用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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM