我有一组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上看到了这种放缓。
测试环境使用的是码头--这能让事情慢下来吗?
发布于 2021-08-27 17:20:40
hp.sphtfunc.smoothing结果是非常计算密集型的,短暂地将流道上的所有16个线程的利用率提高到60%左右。在测试环境中,这同时运行在python 3.6、3.7和3.8上,造成了瓶颈。例如,如果我自己测试3.6,我就得到了~5e-04的预期平均时间。
发布于 2021-08-27 16:10:47
这真的很奇怪,我在我的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或相反的方式。最后一个测试将是从源构建。
https://stackoverflow.com/questions/68949493
复制相似问题