Shared memory windows let processes on the same node access shared memory directly. MPI_Win_allocate_shared allocates a region visible to all processes, avoiding message overhead.
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.