Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active January 24, 2024 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/da4a43902ba4594d157e4ae44f231e75 to your computer and use it in GitHub Desktop.
Save scivision/da4a43902ba4594d157e4ae44f231e75 to your computer and use it in GitHub Desktop.
Python print basic version info and hostname

Python Numpy array allocation test

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}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment