我编写了一个程序,它使用mpi4py在以下代码的0级节点中完成某项工作(制作数组)。然后它在秩1的节点中生成另一个数组。然后我绘制两个数组。节点0中的数组广泛转换为节点1.但是代码会产生奇怪的错误。 我使用了以下命令:
mpiexec -n 2 -f mfile python mpi_test_4.py
该计划如下:
from mpi4py import MPI
import matplotlib.pyplot as plt
import numpy as np
comm = MPI.COMM_WORLD
rank = comm.rank
x = np.linspace(-2*np.pi,2*np.pi,100)
if (rank == 0 ):
y1 = np.sin(x)
else:
y1 = None
y1 = comm.bcast(y1,root=0)
if ( rank == 1 ):
y2 = np.cos(x)
fig = plt.figure()
ax = fig.gca()
ax.plot(x,y1)
ax.plot(x,y2)
plt.savefig('test.png')
print(rank)
错误信息是:
0
QXcbConnection: Could not connect to display
===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= PID 6804 RUNNING AT 192.168.1.106
= EXIT CODE: 134
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
[proxy:0:0@alankar-Aspire-E5-571] HYD_pmcd_pmip_control_cmd_cb (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/pm/pmiserv/pmip_cb.c:885): assert (!closed) failed
[proxy:0:0@alankar-Aspire-E5-571] HYDT_dmxu_poll_wait_for_event (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/tools/demux/demux_poll.c:76): callback returned error status
[proxy:0:0@alankar-Aspire-E5-571] main (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/pm/pmiserv/pmip.c:206): demux engine error waiting for event
[mpiexec@alankar-Aspire-E5-571] HYDT_bscu_wait_for_completion (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/tools/bootstrap/utils/bscu_wait.c:76): one of the processes terminated badly; aborting
[mpiexec@alankar-Aspire-E5-571] HYDT_bsci_wait_for_completion (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/tools/bootstrap/src/bsci_wait.c:23): launcher returned error waiting for completion
[mpiexec@alankar-Aspire-E5-571] HYD_pmci_wait_for_completion (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/pm/pmiserv/pmiserv_pmci.c:218): launcher returned error waiting for completion
[mpiexec@alankar-Aspire-E5-571] main (/home/alankar/mpich3/mpich-3.2/src/pm/hydra/ui/mpich/mpiexec.c:344): process manager error waiting for completion
然而,当我在节点0上绘图时,这是我用来发出命令的节点:mpiexec -n 2 -f mfile python mpi_test_4.py代码有效。例如:
from mpi4py import MPI
import matplotlib.pyplot as plt
import numpy as np
comm = MPI.COMM_WORLD
rank = comm.rank
x = np.linspace(-2*np.pi,2*np.pi,100)
if (rank == 1 ):
y1 = np.sin(x)
else:
y1 = None
y1 = comm.bcast(y1,root=1)
if ( rank == 0 ):
y2 = np.cos(x)
fig = plt.figure()
ax = fig.gca()
ax.plot(x,y1)
ax.plot(x,y2)
plt.savefig('test.png')
print(rank)
答案 0 :(得分:1)
这个错误绝不是奇怪的。 "无法连接显示"意味着某些东西无法做一些图形的东西。鉴于MPI进程可以在不同的计算节点上运行,您无法保证任何排名都能做到这一点。根据{{3}},您应该能够强制matplotlib使用不同的后端:
import matplotlib
matplotlib.use('Agg')