NUMA node allocation for NumPy arrays on Linux
# Ubuntu/Debian
sudo apt install libnuma-dev
# Fedora/CentOS
sudo dnf install numactl-devel
# pypi
pip install npynumaimport numpy as np
from npynuma import NumaPolicy
with NumaPolicy(node=1): # Allocate on NUMA node 1
large_array = np.empty(10_000_000) # 80MB array on node 1
# Works with existing numpy functions
with NumaPolicy(node=0):
random_data = np.random.normal(size=1_000_000)- Requires Linux NUMA system (
numactlinstalled) - Node numbers must exist on your system
NumaPolicy contexts concurrently in:
- Multithreaded applications
- Async frameworks
- Any parallel code sharing NumPy allocations