首页 > 解决方案 > 远程 Linux 机器上的healpy.sphtfunc.smoothing 花费的时间是本地 Mac 的 2800 倍

问题描述

我有一组healpy要模糊的地图healpy.sphtfunc.smoothing。事情在我的 Macbook Pro 上运行顺利,但在我们用于测试的远程 Linux 机器上,我发现测试停滞不前,因为healpy.sphtfunc.smoothing在某些情况下需要 2700 倍的时间来执行!这是一个MWE:

def test_hp_smooth_mwe():
    import numpy as np
    import os, platform, sys, time
    import healpy as hp
    print(os.name, platform.system(), platform.release())
    print(hp.__version__)
    print(sys.version)
    resp_matrix = 10 * np.random.random(size=(5, 64, 768))
    times = np.zeros((5, 64))
    for i in range(resp_matrix.shape[0]):
        for j in range(resp_matrix.shape[1]):
            t0 = time.time()
            resp_matrix[i, j, :] = hp.sphtfunc.smoothing(
                resp_matrix[i, j, :], fwhm=np.deg2rad(10)
            )
            times[i, j] = time.time() - t0
    assert False, f"mean smoothing time: {times.mean():.3e} s"

我的 Macbook Pro 结果:

posix Darwin 18.7.0
1.15.0
3.8.10 | packaged by conda-forge | (default, May 10 2021, 22:58:09) 
[Clang 11.1.0 ]
AssertionError: mean smoothing time: 4.865e-04 s

远程Linux机器结果,在测试环境中运行:

posix Linux 5.8.0-43-generic
1.15.0
3.6.14 (default, Aug 17 2021, 16:32:35) 
[GCC 10.2.1 20210110]
AssertionError: mean smoothing time: 1.360e+00 s

远程 Linux 机器结果,在 Python 解释器中运行:

posix Linux 5.8.0-43-generic
1.15.0
3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0]
AssertionError: mean smoothing time: 3.423e-04 s

(不要介意奇怪的导入模式和assert False,这只是为了让它在远程测试机器上轻松工作。)

正如我们所见,在远程 Linux 测试环境中进行平滑处理所需的时间是本地机器上的 2800 倍。据我所知,没有其他操作经历如此剧烈的减速,只是平滑。另请注意,我在 python 3.6、3.7 和 3.8 上看到了这种放缓。

测试环境使用 docker——这会减慢速度吗?

标签: pythonperformancenumpyhealpy

解决方案


这真的很奇怪,我在我的 Linux 笔记本电脑上进行了测试,我得到:

posix Linux 5.4.119-14945-gafc97d54f809
1.15.0
3.8.0 (default, Nov  6 2019, 21:49:08) 
[GCC 7.3.0]
mean smoothing time: 5.515e-04 s

差异似乎很大,可以用线程问题来解释,但您也许可以检查链接是否有奇怪之处:

ldd _healpy_sph_transform_lib.cpython-38-x86_64-linux-gnu.so
        linux-vdso.so.1 (0x00007ffe29b71000)
        libcurl-8a7386dc.so.4.7.0 => /home/zonca/miniconda3/envs/simple/lib/python3.8/site-packages/healpy/./../healpy.libs/libcurl-8a7386dc.so.4.7.0 (0x00007e31b0462000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007e31b02cf000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007e31b014c000)
        libgomp-3300acd3.so.1.0.0 => /home/zonca/miniconda3/envs/simple/lib/python3.8/site-packages/healpy/./../healpy.libs/libgomp-3300acd3.so.1.0.0 (0x00007e31aff3c000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007e31aff22000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007e31afeff000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007e31afd3e000)
        libz-a147dcb0.so.1.2.3 => /home/zonca/miniconda3/envs/simple/lib/python3.8/site-packages/healpy/./../healpy.libs/libz-a147dcb0.so.1.2.3 (0x00007e31afb29000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007e31afb24000)
        /lib64/ld-linux-x86-64.so.2 (0x00007e31b0f93000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007e31afb1a000)

我会尝试healpy从其他来源安装。因此,如果您使用 Conda 安装,请尝试 pip 或其他方式。最后一个测试是从源代码构建。


推荐阅读