Site Tools


shared-memory-windows-mpi

Table of Contents

Shared memory windows (MPI)

On a multi-core node, MPI processes communicate through the messaging layer by default, even when they share the same physical memory. A send between two processes on the same node still involves serialisation overhead and memory copies that shared memory would avoid. MPI_Win_allocate_shared allocates a contiguous region visible to all processes in the communicator as a direct pointer — the same model as mmap with MAP_SHARED — with no send/recv overhead. The window is divided into per-process segments; each process specifies the size of its own.

MPI_Win win;
double *local_ptr;
MPI_Win_allocate_shared(N * sizeof(double), sizeof(double),
                        MPI_INFO_NULL, MPI_COMM_WORLD, &local_ptr, &win);
 
// get a pointer directly into another process's segment
MPI_Aint seg_size; int disp_unit; double *remote_ptr;
MPI_Win_shared_query(win, target_rank, &seg_size, &disp_unit, &remote_ptr);
 
MPI_Win_fence(0, win);
remote_ptr[i] = 1.0;    // direct write; no MPI_Put needed
MPI_Win_fence(0, win);
 
MPI_Win_free(&win);

MPI_Win_allocate_shared only works when all processes in the communicator are on the same node. MPI_Comm_split_type with MPI_COMM_TYPE_SHARED is the standard way to create such a communicator. Synchronisation still requires fences or locks. This is most useful in hybrid programs where the shared-memory work would otherwise be handled by OpenMP, but where keeping a uniform MPI programming model is preferable.

shared-memory-windows-mpi.txt · Last modified: by 127.0.0.1