6.4. Memory Management¶
This section describes how \({\mathcal H}\Phi\) manages memory for large-scale calculations.
6.4.1. Memory Requirements¶
The dominant memory usage in \({\mathcal H}\Phi\) comes from storing the state vectors. For a Hilbert space of dimension \(D\) distributed across \(P\) MPI processes, each process requires:
- Lanczos method
Two state vectors (
v0,v1): \(2 \times D/P \times 16\) bytes (complex double)One buffer for MPI communication: \(D/P \times 16\) bytes
- LOBPCG method
Multiple state vectors for subspace iteration
Buffer for orthogonalization
- List arrays
list_1: \(D/P \times 8\) bytes (unsigned long)list_2_1,list_2_2: depends on system size
6.4.2. Memory Allocation¶
\({\mathcal H}\Phi\) allocates memory dynamically using wrapper functions defined in
common/setmemory.c. These functions handle allocation for various data types:
d_1d_allocate: 1D double arraycd_1d_allocate: 1D complex double arrayi_2d_allocate: 2D integer arraylui_1d_allocate: 1D unsigned long integer array
Memory is allocated at the beginning of the calculation in xsetmem.c and
freed at the end.
6.4.3. Estimating Memory Usage¶
Before running a calculation, you can estimate the required memory:
where:
\(D\) is the Hilbert space dimension
\(P\) is the number of MPI processes
\(N_v\) is the number of state vectors (typically 3-4 for Lanczos)
\(N_l\) is the number of list arrays (typically 1-3)
- Example
For a 16-site Hubbard model with 4 up and 4 down electrons (\(S_z = 0\)):
Hilbert space: \(D = \binom{16}{4}^2 = 1,820^2 = 3,312,400\)
With 4 MPI processes: \(D/P = 828,100\) states per process
Memory per process: approximately 50 MB for state vectors
6.4.4. Memory Optimization Strategies¶
- Increasing MPI processes
Distributing the Hilbert space across more processes reduces per-process memory requirements.
- Using symmetries
Particle number conservation, \(S_z\) conservation, and other symmetries reduce the Hilbert space dimension.
- Restart functionality
For very large calculations, the restart feature allows breaking the calculation into smaller chunks.
6.4.5. Common Memory Issues¶
- Out-of-memory errors
If the calculation runs out of memory, try:
Increase the number of MPI processes
Use symmetry restrictions
Request more memory per node on cluster systems
- Memory leaks
\({\mathcal H}\Phi\) carefully manages memory to avoid leaks. If you observe growing memory usage, please report it as a bug.