MPI_WIN_ALLOCATE(3)

🌸 MPI_Win_allocate 🌸

okay bestie, welcome to the Open MPI manual (section 3, the library calls girlies πŸ’…). This is MPI_Win_allocate β€” the one-sided MPI call that allocates memory AND hands you back a window object for RMA operations. Two for one, no cap. πŸŽ€


✨ SYNTAX ✨

πŸ’œ C Syntax

#include <mpi.h>

int MPI_Win_allocate (MPI_Aint size, int disp_unit, MPI_Info info,
                      MPI_Comm comm, void *baseptr, MPI_Win *win)

πŸ’œ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_WIN_ALLOCATE(SIZE, DISP_UNIT, INFO, COMM, BASEPTR, WIN, IERROR)
     INTEGER(KIND=MPI_ADDRESS_KIND) SIZE, BASEPTR
     INTEGER DISP_UNIT, INFO, COMM, WIN, IERROR

πŸ’œ Fortran 2008 Syntax

USE mpi_f08
MPI_Win_allocate(size, disp_unit, info, comm, baseptr, win, ierror)
     USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
     INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: size
     INTEGER, INTENT(IN) :: disp_unit
     TYPE(MPI_Info), INTENT(IN) :: info
     TYPE(MPI_Comm), INTENT(IN) :: comm
     TYPE(C_PTR), INTENT(OUT) :: baseptr
     TYPE(MPI_Win), INTENT(OUT) :: win
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🫢 INPUT PARAMETERS 🫢

  • size β€” the size of the window, in bytes. It's a nonnegative integer, so zero is allowed, we love a fresh-slate moment. ✨
  • disp_unit β€” the local unit size for displacements, in bytes. Positive integer only, bestie, keep it cute. πŸ”₯
  • info β€” the info argument (a handle).
  • comm β€” the communicator (a handle).

πŸ’– OUTPUT PARAMETERS πŸ’–

  • baseptr β€” the initial address of the window.
  • win β€” the window object the call gives back to you (a handle). She's yours now. πŸ‘‘
  • ierror β€” Fortran only: the error status, as an integer.

🌈 DESCRIPTION 🌈

So. MPI_Win_allocate is a collective call, meaning every single process in the group of comm has to show up for it β€” no ditching, it's giving group project energy, but like, the good kind. On each process it:

  • allocates memory of at least size bytes,
  • returns a pointer to that memory,
  • and returns a window object that every process in comm can use to do RMA operations. πŸ¦‹

The memory you get back is size bytes local to each process, starting at address baseptr, and it's associated with the window as if you had called MPI_Win_create on existing memory. The size argument can legitimately be different on every process, and size = 0 is valid β€” but heads up, a library might allocate and expose more memory than you asked for, in order to create a fast, globally symmetric allocation. It's not being sneaky, it's being efficient. πŸ’…

The discussion of, and the rationales for, MPI_Alloc_mem and MPI_Free_mem in MPI-3.1 section 8.2 also apply to MPI_Win_allocate. In particular, go read the rationale in MPI-3.1 section 8.2 if you want the explanation of why baseptr has the type that it has. πŸ“š

Now, the displacement unit argument exists to make address arithmetic in RMA operations easier: the target displacement argument of an RMA operation gets scaled by the factor disp_unit specified by the target process, back when the window was created.

For the supported info keys, go see MPI_Win_create. πŸ”‘


πŸŽ€ NOTES πŸŽ€

Common choices for disp_unit are 1 (aka no scaling at all, a minimalist queen) and, in C syntax, sizeof(type) β€” that one's for when your window is an array of elements of type type. That second choice lets you use array indices in your RMA calls and have them scaled correctly into byte displacements, even in a heterogeneous environment. Slay. ✨

Calling MPI_Win_free will deallocate the memory that MPI_Win_allocate allocated. Which means it is erroneous to manually free baseptr yourself. Do NOT double-free, bestie, I am begging. 😭


πŸ’€ C NOTES πŸ’€

So baseptr is declared as a void * type β€” but that's only to let you easily pass any pointer object for this parameter. This argument is really a void ** type. It's giving costume party. 🎭


πŸ”₯ ERRORS πŸ”₯

Almost all MPI routines return an error value: C routines do it as the return result of the function, and Fortran routines do it in the last argument. Classic.

Before that error value ever comes back to you, the current MPI error handler associated with the communication object (e.g., communicator, window, file) gets called. If there's no communication object associated with the MPI call, then the call counts as attached to MPI_COMM_SELF and will call the associated MPI error handler. And when MPI_COMM_SELF is not initialized β€” meaning before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when you're using the Sessions Model exclusively β€” the error raises the initial error handler. 😳

That initial error handler can be changed by:

  • calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model, or
  • the mpi_initial_errhandler CLI argument to mpiexec, or
  • the info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple.

And if no other appropriate error handler has been set, then MPI_ERRORS_RETURN gets called for MPI I/O functions, while MPI_ERRORS_ABORT gets called for all other MPI functions. That's just how it is. πŸ’…

Open MPI includes three predefined error handlers you can use:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. Very much the nuclear option.
  • MPI_ERRORS_ABORT β€” an error handler that can be invoked on a communicator, window, file, or session. When called on a communicator, it acts as if MPI_Abort was called on that communicator. If called on a window or file, it acts as if MPI_Abort was called on a communicator containing the group of processes in the corresponding window or file. If called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application. The chill one.

MPI applications can also implement their own error handlers by calling:

  • MPI_Comm_create_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_Win_set_errhandler
Note that MPI does not guarantee that an MPI program can continue past an error. Read that again, bestie. 🚨

See the MPI man page for a full list of MPI error codes.

See the Error Handling section of the MPI-3.1 standard for more information.

See also:

  • MPI_Alloc_mem
  • MPI_Free_mem
  • MPI_Win_create
  • MPI_Win_allocate_shared
  • MPI_Win_free

Copyright 2003-2026, The Open MPI Community.


and that's the whole page, bestie!! 🫢 this Open MPI manual page (MPI_WIN_ALLOCATE(3), section 3) was dated Sep 10, 2026, copyright 2003-2026, The Open MPI Community β€” go forth and allocate responsibly, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from