Skip to content

Time and memory efficient parallelization#81

Open
antelmor wants to merge 23 commits intomailhexu:mainfrom
antelmor:main
Open

Time and memory efficient parallelization#81
antelmor wants to merge 23 commits intomailhexu:mainfrom
antelmor:main

Conversation

@antelmor
Copy link
Copy Markdown
Contributor

@antelmor antelmor commented Feb 3, 2026

Summary

Introduces a new parallelization scheme designed to improve both runtime performance and memory efficiency for computing Green’s functions and the $A_{ij}$ exchange tensor.

The core of this update is a new lightweight execution object, GreenRuntime, whose sole responsibility is to perform the heavy numerical work while minimizing memory footprint and inter-process communication overhead.


Key Design Changes

1. GreenRuntime: lightweight compute runner

  • Introduces a dedicated GreenRuntime object that encapsulates only the minimal information required to compute Green’s functions and the $A_{ij}$ tensor.
  • Heavy data structures from initialization (e.g. full tight-binding Hamiltonians) are not stored, unlike in ExchangeNCL or TBGreen.
  • Avoids large intermediate dictionaries in favor of contiguous NumPy arrays, improving cache efficiency and serialization speed.

2. Efficient multiprocessing via np.memmap

  • Large arrays are stored using np.memmap, ensuring:
    • Minimal memory duplication across processes
    • Reduced inter-process communication overhead
    • Safe scaling to larger systems
  • This design enables faster multiprocessing without increasing memory pressure.

3. Cross-platform multiprocessing support

  • The new scheme is compatible with both multiprocessing start methods:
    • 'fork' (Linux)
    • 'spawn' (macOS, Windows)
  • This ensures portability across operating systems without changes to the execution logic.

4. Thread control via threadpoolctl

  • Adds threadpoolctl support to limit the number of threads used by NumPy/SciPy backends.
  • Prevents thread oversubscription, which can otherwise degrade performance when combined with multiprocessing.

Additional Fixes

  • Fixed Python syntax in magnons/io_exchange2.py that previously required Python ≥ 3.11.
  • The module is now compatible with older Python versions, restoring usability of the magnon scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant