Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Importing Numpy very CPU-intensive with non-small thread count #29193

Open
@pitrou

Description

@pitrou

Describe the issue:

On my machine, Numpy takes a lot of CPU time to import:

$ \time python -c "import numpy"
1.28user 0.01system 0:00.07elapsed 1742%CPU (0avgtext+0avgdata 25648maxresident)k
0inputs+0outputs (0major+3569minor)pagefaults 0swaps

If I reduce the thread count, importing is much faster:

$ OMP_NUM_THREADS=1 \time python -c "import numpy"
0.05user 0.01system 0:00.06elapsed 98%CPU (0avgtext+0avgdata 25744maxresident)k
0inputs+0outputs (0major+3474minor)pagefaults 0swaps

Reproduce the code example:

import numpy

Error message:

Python and NumPy Versions:

2.3.0
3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0]

Runtime Environment:

[{'numpy_version': '2.3.0',
'python': '3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0]',
'uname': uname_result(system='Linux', node='martenot', release='6.11.0-26-generic', version='#26~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 17 19:20:47 UTC 2', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'architecture': 'Haswell',
'filepath': '/home/antoine/t/venv-3.12/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so',
'internal_api': 'openblas',
'num_threads': 24,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.29'}]

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions