Simple check that a system can allocate a large numpy array.
python array_allocate.py
#!/usr/bin/env python3 | |
""" | |
print a few system basics | |
verify system can allocate a multi-gigabyte array | |
""" | |
import numpy as np | |
import sys | |
import platform | |
import socket | |
import logging | |
print(platform.node()) | |
print(socket.getfqdn()) | |
print(f"Python {sys.version}") | |
print(f"Numpy {np.__version__}") | |
GIB = 1073741824 | |
try: | |
import psutil | |
avail_memory = psutil.virtual_memory().available | |
print( | |
f"RAM (GiB): available {avail_memory/GIB:.1f}" | |
f" total {psutil.virtual_memory().total/GIB:.1f}" | |
) | |
except ImportError: | |
logging.warning( | |
"""to get RAM info, do (one-time): | |
pip install psutil""" | |
) | |
# can the system allocate enough RAM for the desired array | |
Nx = 1024 | |
Ny = 768 | |
Nz = 512 | |
Np = 3 | |
x = np.empty((Nz, Nx, Ny, Np), dtype=np.float64) | |
print(f"array shape {x.shape} memory (GiB) {x.nbytes/GIB:.1f}") |