Skip to content

Introducing MPI shared memory based weight pre-processing - #29

Merged
anand-avinash merged 125 commits into
mainfrom
shmem
Aug 7, 2026
Merged

anand-avinash merged 125 commits into
mainfrom
shmem

Conversation

@anand-avinash

@anand-avinash anand-avinash commented Jul 15, 2026 •

Copy link
Copy Markdown
Owner

This PR introduces SharedMemProcessTimeSamples, an MPI shared-memory optimized alternative to the standard ProcessTimeSamples data container. It utilizes MPI shared-memory features (via mpi4py and custom C++ bindings) to significantly reduce the memory footprint when preprocessing pointing information and map-making weights across multi-process, multi-node environments. Consequently, it also reduces the amount of inter-node MPI communication significantly.

Instead of replicating the pixel-space data structures (such as hit counts and trigonometric weights) on every MPI process on a node, SharedMemProcessTimeSamples allocates node-level shared-memory windows, aggregates weights using sub-communicators, and makes the results visible across all node ranks.

The implementation details are as follows:

  1. Shared memory allocator/manager on Python side: The changes include the implementation of a shared memory allocator/manager (SharedMemoryManager in mpi.py). It provides an interface to split a given MPI communicator into communicators with shared memory access. It also implements a robust communicator split hierarchy (_node_comm, _node_root_comm, _tree_grp_comm, _tree_grp_root_comm) for shared memory topologies and correctly allocates NumPy arrays backed by shared MPI windows with MPI.Win.Allocate_shared.

  2. Shared memory allocator/manager on C++ side: We have implemented an analogous shared memory allocator/manager on the C++ side in mpi_utils.hpp to allow direct allocation and querying of MPI shared windows in C++ routines.

  3. Implementation of SharedMemProcessTimeSamples: It is a shared memory analogue of the classic ProcessTimeSamples container. While it exposes the same attributes as ProcessTimeSamples, they point to shared-memory buffers that are allocated only once for each shared memory domain (usually a single compute node). The corresponding C++ backends are defined in compute_weights_shared.cpp.

Additionally, this PR updates documentation and refactors multiple tests to use fixtures, which improves efficiency and reduces code repetition.

…ons. The serial ones are transferred to compute_weights_commons.cpp
…mons to compute_weights to simplify the workflow in prospective compute_weights_shared
…yManager class to facilitate allocating MPI shared memory from python side
…TimeSamples to make them the sub class of BaseProcessTimeSamples
…ager from Comm object to Comm.handle, as Comm is not hashable - and can't be used as a dict key
….cpp to ensure that the fence calls are made globally in order to avoid deadlocks
…o SharedMemProcessTimeSamples to enable freeing shared memory window allocated by it
… memory PTS to free shared memory arrays appropriately
…that frees shared memory window, arrays, and the communicators created by the manager; updated the relevant tests to use the new method
… and iterations through benchmarks.pedantic() function to prevent segmentation fault in running benchmark on mpi related functions; added cli args to supply number of rounds, iterations, and warmup rounds
… after each round whenever a shared memory time samples container is created
@anand-avinash
anand-avinash marked this pull request as ready for review August 6, 2026 11:09
… level arrays are allocated unconditionally irrespective of whether nproc_reduce is one or greater; this prevents race condition led by multiple grp comm level arrays writing to same node root arrays at the same time whenever nproc_reduce was one
…ension; now grp comm level arrays are allocated unconditionally irrespective of whether nproc_reduce is one or greater
…ved grp_reduce arguments from benchmark tests
@anand-avinash
anand-avinash merged commit e8d1bc7 into main Aug 7, 2026
16 of 32 checks passed
@anand-avinash
anand-avinash deleted the shmem branch August 7, 2026 15:20
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