MPI_Win_allocate_shared(3)
π MPI_Win_allocate_shared(3) π
okay bestie, sit DOWN, because this one is genuinely iconic. this is part of the MPI manual (yes, that MPI, the message-passing one, the blueprint of parallel computing, the moment) π«Ά
β¨ NAME β¨
MPI_Win_allocate_shared β make an MPI Window object so you can do one-sided communication and shared memory access, plus allocate memory at every process. two for the price of one, slay π
πΈ SYNOPSIS πΈ
int MPI_Win_allocate_shared(MPI_Aint size, int disp_unit, MPI_Info info,
MPI_Comm comm, void *baseptr, MPI_Win *win)
int MPI_Win_allocate_shared_c(MPI_Aint size, MPI_Aint disp_unit, MPI_Info info,
MPI_Comm comm, void *baseptr, MPI_Win *win)
π INPUT PARAMETERS π
sizeβ the size of the local window, in bytes (a non-negative integer, so zero is allowed, no gatekeeping)disp_unitβ the local unit size for displacements, in bytes (a positive integer, so keep it above zero pls)infoβ the info argument (a handle)commβ an intra-communicator (a handle)
π¦ OUTPUT PARAMETERS π¦
baseptrβ the address of the locally allocated window segment (a choice)winβ the window object the call hands back to you (a handle)
okay so this is a collective call β everybody in the group of comm has to run it together, no main character behavior where one process goes off alone π on each process i, it allocates at least size bytes of memory that's shared among all processes in comm, and drops a pointer to the locally allocated segment into baseptr, which you can use for load/store accesses on the process that's calling. the locally allocated memory can also be the target of load/store accesses from remote processes β and if you want the base pointers for those other processes, just query them with MPI_Win_shared_query π
the call also gives you back a window object that every process in comm can use to do RMA operations. the size argument can be different at each process, and size = 0 is fully valid, not a typo, we love a flexible queen. it's your responsibility to make sure the communicator comm represents a group of processes that can actually create a shared memory segment that all of them can access β that part is on you, bestie, not on the library.
the allocated memory is contiguous across process ranks unless the info key alloc_shared_noncontig is specified. and when we say "contiguous across process ranks," we mean the first address in the memory segment of process i sits consecutive with the last address in the memory segment of process i - 1. that little trick may let you calculate remote address offsets using local information only, which is giving very much β¨efficiencyβ¨
π₯ THREAD AND INTERRUPT SAFETY π₯
this routine is thread-safe, periodt. that means multiple threads can safely use it without you needing to bring your own user-provided thread locks β the library handles it, you're welcome π
however (and this is the plot twist), the routine is not interrupt safe π typically that's because it uses memory allocation routines like malloc, or other non-MPICH runtime routines, and those are themselves not interrupt-safe. so keep your signals away from it, fr fr.
π NOTES FOR FORTRAN π
every MPI routine in Fortran (except MPI_WTIME and MPI_WTICK) has one extra argument at the end of the argument list: ierr. ierr is an integer and means the same thing as the return value of the routine in C. and in Fortran, MPI routines are subroutines, invoked with the call statement. so fancy.
all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. that's just how Fortran rolls π
π ERRORS π
all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value β C routines as the value of the function, and Fortran routines in that last argument. before the value comes back to you, the current MPI error handler gets called. by default this error handler aborts the MPI job, so yeah, that's the dramatic one π the error handler can be swapped out with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). there's also the MPI-1 routine MPI_Errhandler_set, which may be used, but heads up: its use is deprecated. the predefined error handler MPI_ERRORS_RETURN may be used to make error values get returned instead.
also, MPI does not guarantee that a program can continue past an error β but MPI implementations will attempt to continue whenever possible. optimistic kings π
MPI_SUCCESSβ no error, the MPI routine completed successfully, we ate πMPI_ERR_ARGβ invalid argument. some argument is invalid and isn't identified by a specific error class (e.g.MPI_ERR_RANK).MPI_ERR_COMMβ invalid communicator. a common error is using a null communicator in a call (not even allowed inMPI_Comm_rank, so don't try it).MPI_ERR_DISPβ (no description given, she's mysterious)MPI_ERR_INFOβ invalid InfoMPI_ERR_SIZEβ (also mysterious, no description)MPI_ERR_OTHERβ other error; useMPI_Error_stringto get more information about this error code.
π SEE ALSO π
MPI_Win_allocateMPI_Win_createMPI_Win_create_dynamicMPI_Win_freeMPI_Win_shared_query
that's the whole thing bestie, you're officially a shared-memory window girlie now π§
MPI_Win_allocate_shared(3) Β· from the MPI manual Β· last updated 4/10/2026 Β· ily, go allocate something beautiful πβ¨
π¦ where this page comes from
- nixos 26.05: mpich 5.0.1
- ubuntu stonking: mpich-doc 5.0.1-9 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms