MPI_Win_allocate_shared(3)

πŸ“¦
version 5.0.1 Β· 5 versions
, in nixos 26.05, ubuntu stonking

πŸ’– 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 in MPI_Comm_rank, so don't try it).
  • MPI_ERR_DISP β€” (no description given, she's mysterious)
  • MPI_ERR_INFO β€” invalid Info
  • MPI_ERR_SIZE β€” (also mysterious, no description)
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code.

🌈 SEE ALSO 🌈

  • MPI_Win_allocate
  • MPI_Win_create
  • MPI_Win_create_dynamic
  • MPI_Win_free
  • MPI_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