【发布时间】:2015-05-24 02:18:37
【问题描述】:
我有一个 python 脚本,它招募 MPI 进行并行计算。计算方案如下:数据处理第 1 轮 - 进程之间的数据交换 - 数据处理第 2 轮。我有一台 16 逻辑核心机器(2 x Intel Xeon E5520 2.27GHz)。由于某种原因,第一轮不能并行运行。因此,15 个核心保持空闲状态。然而,尽管如此,计算速度却下降了 2 倍以上。
这个脚本说明了问题(另存为test.py):
from mpi4py import MPI
import time
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
comm.barrier()
stime = time.time()
if rank == 0:
print('begin calculations at {:.3f}'.format(time.time() - stime))
for i in range(1000000000):
a = 2 * 2
print('end calculations at {:.3f}'.format(time.time() - stime))
comm.bcast(a, root = 0)
print('end data exchange at {:.3f}'.format(time.time() - stime))
else:
a = comm.bcast(root = 0)
当我在 2 个内核上运行它时,我观察到:
$ mpiexec -n 2 python3 test.py
begin calculations at 0.000
end calculations at 86.954
end data exchange at 86.954
当我在 16 核上运行它时,我观察到:
$ mpiexec -n 16 python3 test.py
begin calculations at 0.000
end calculations at 174.156
end data exchange at 174.157
谁能解释这种差异?一个想法,如何摆脱它,也会很有用。
【问题讨论】:
标签: python performance mpi