【问题标题】:mpi4py: substantial slowdown by idle coresmpi4py:空闲内核显着放缓
【发布时间】: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


    【解决方案1】:

    好的,我终于想通了。

    有几个特点导致了减速:

    • 等待数据接收处于活动状态(它会不断检查数据是否已经到达),这使得等待进程不再空闲。
    • Intel 虚拟内核不影响计算速度。这意味着,8 核机器仍然是 8 核,其行为与虚拟机无关(在某些情况下,例如,当应用 multithreading 模块时,它们可以进行适度的提升,但不能使用 MPI)。李>

    考虑到这一点,我修改了代码,将 sleep() 函数引入到等待进程中。结果显示在图表上(每种情况下进行了 10 次测量)。

    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:
        for i in range(1000000000):
            a = 2 * 2
        print('end calculations at {:.3f}'.format(time.time() - stime))
        for i in range(1, size):
            comm.send(a, dest = i)
        print('end data exchange at {:.3f}'.format(time.time() - stime))
    else:
        while not comm.Iprobe(source = 0):
            time.sleep(1)
        a = comm.recv(source = 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-25
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 2020-03-15
      • 1970-01-01
      相关资源
      最近更新 更多