Global Configuration Options#
NumPy has a few import-time, compile-time, or runtime configurationoptions which change the global behaviour. Most of these are related toperformance or for debugging purposes and will not be interesting to thevast majority of users.
Performance-related options#
Number of threads used for linear algebra#
NumPy itself is normally intentionally limited to a single threadduring function calls, however it does support multiple Pythonthreads running at the same time.Note that for performant linear algebra NumPy uses a BLAS backendsuch as OpenBLAS or MKL, which may use multiple threads that maybe controlled by environment variables such asOMP_NUM_THREADSdepending on what is used.One way to control the number of threads is the packagethreadpoolctl
madvise hugepage on Linux#
When working with very large arrays on modern Linux kernels,you can experience a significant speedup whentransparent hugepageis used.The current system policy for transparent hugepages can be seen by:
cat/sys/kernel/mm/transparent_hugepage/enabled
When set tomadvise NumPy will typically use hugepages for a performanceboost. This behaviour can be modified by setting the environment variable:
NUMPY_MADVISE_HUGEPAGE=0
or setting it to1 to always enable it. When not set, the defaultis to use madvise on Kernels 4.6 and newer. These kernels presumablyexperience a large speedup with hugepage support.This flag is checked at import time.
SIMD feature selection#
SettingNPY_DISABLE_CPU_FEATURES will exclude simd features at runtime.SeeRuntime Dispatch.
Debugging-related options#
Warn if no memory allocation policy when deallocating data#
Some users might pass ownership of the data pointer to thendarray bysetting theOWNDATA flag. If they do this without setting (manually) amemory allocation policy, the default will be to callfree. IfNUMPY_WARN_IF_NO_MEM_POLICY is set to"1", aRuntimeWarning willbe emitted. A better alternative is to use aPyCapsule with a deallocatorand set thendarray.base.
Changed in version 1.25.2:This variable is only checked on the first import.