[英]Multiple instances of Python running simultaneously limited to 35
我在並行計算集群的不同處理器上運行Python 3.6腳本作為多個單獨的進程。 最多35個進程同時運行沒有問題,但第36行(以及更多)在第二行崩潰並且import pandas as pd
。 有趣的是,第一行import os
不會引起問題。 完整的錯誤消息是:
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
Traceback (most recent call last):
File "/home/.../myscript.py", line 32, in <module>
import pandas as pd
File "/home/.../python_venv2/lib/python3.6/site-packages/pandas/__init__.py", line 13, in <module>
__import__(dependency)
File "/home/.../python_venv2/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/home/.../python_venv2/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/.../python_venv2/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/.../python_venv2/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/.../python_venv2/lib/python3.6/site-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
SystemError: initialization of multiarray raised unreported exception
/var/spool/slurmd/job04590/slurm_script: line 11: 26963 Segmentation fault python /home/.../myscript.py -x 38
Pandas和一些其他軟件包安裝在虛擬環境中。 我復制了虛擬環境,因此每個venv中運行的進程不超過24個。 例如,上面的錯誤腳本來自在虛擬環境中運行的名為python_venv2
的腳本。
無論有多少進程從特定的Pandas實例導入,每次都會在第36個進程上發生此問題。 (我甚至沒有削弱並行計算集群的能力。)
因此,如果它不是對訪問Pandas的進程數量的限制,那么它是否限制了運行Python的進程數量? 為什么35是限制?
是否可以在機器上安裝多個Python副本(在單獨的虛擬環境中?),這樣我就可以運行超過35個進程?
分解錯誤消息
您的錯誤消息包括以下提示:
OpenBLAS blas_thread_init: pthread_create: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 1024 current, 2067021 max
RLIMIT_NPROC
變量控制用戶可以擁有的進程總數。 更具體地說,由於它是每個進程設置,當進程調用fork()
, clone()
, vfork()
和c時,該進程的RLIMIT_NPROC
值將與該進程的父用戶的總進程數進行比較。 如果超過這個值,事情會因為你的經歷而關閉。
該錯誤消息表明OpenBLAS無法創建其他線程,因為您的用戶已使用RLIMIT_NPROC
提供的所有線程。
由於您在群集上運行,因此您的用戶不太可能運行多個線程(例如,如果您在個人計算機上並瀏覽網頁,播放音樂等),因此可以合理地斷定OpenBLAS正在嘗試啟動多個線程。
OpenBLAS如何使用線程
OpenBLAS可以使用多個線程來加速線性代數。 您可能需要許多線程來快速解決單個更大的問題。 您可能需要更少的線程來同時解決許多小問題。
OpenBLAS有幾種方法可以限制它使用的線程數。 通過以下方式控制:
export OPENBLAS_NUM_THREADS=4
export GOTO_NUM_THREADS=4
export OMP_NUM_THREADS=4
優先級為OPENBLAS_NUM_THREADS> GOTO_NUM_THREADS> OMP_NUM_THREADS。 (我認為這意味着OPENBLAS_NUM_THREADS
會覆蓋OMP_NUM_THREADS
;但是,當使用USE_OPENMP=1
編譯時,OpenBLAS會忽略OPENBLAS_NUM_THREADS
和GOTO_NUM_THREADS
。)
如果沒有設置上述變量,OpenBLAS將使用多個線程運行,這些線程等於機器上的核心數(機器上的32個)
你的情況
您的群集具有32核CPU。 您正在嘗試運行36個Python實例。 每個實例需要1個線程用於Python + 32個線程用於OpenBLAS。 您還需要一個用於SSH連接的線程和一個用於shell的線程。 這意味着您需要36 *(32 + 1)+ 2 = 1190個線程。
解決問題的核選擇是使用:
export OPENBLAS_NUM_THREADS=1
這應該會降低到36 *(1 + 1)+ 2 = 74個線程。
由於您具有備用容量,因此可以將OPENBLAS_NUM_THREADS
調整為更高的值,但隨后由單獨的Python進程擁有的OpenBLAS實例將相互干擾。 因此,在獲得一個解決方案的速度與獲得多個解決方案的速度之間需要進行權衡。 理想情況下,您可以通過每個節點運行更少的Pythons並使用更多節點來解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.