MPI_WIN_ATTACH(3)

🌸 MPI_WIN_ATTACH(3) 🌸

okay bestie, welcome to the MPI_WIN_ATTACH(3) page straight outta the Open MPI manual πŸ’– this is the one about attaching and detaching memory regions to/from a window so you can do RMA (remote memory access) things with them. it's giving one-sided communication and honestly? iconic. let's get into it 🫢


✨ NAME ✨

MPI_Win_attach, MPI_Win_detach β€” the one-sided MPI call duo that attaches / detaches a memory region to / from a window object so it can be used for RMA operations πŸ’…


πŸŽ€ SYNTAX πŸŽ€

πŸ’» C Syntax πŸ’»

#include <mpi.h>

MPI_Win_attach(MPI_Win win, void *base, MPI_Aint size)

MPI_Win_detach(MPI_Win win, void *base)

πŸ¦‹ Fortran Syntax πŸ¦‹

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_WIN_ATTACH(WIN, BASE, SIZE, IERROR)
     <type> BASE(*)
     INTEGER(KIND=MPI_ADDRESS_KIND) SIZE
     INTEGER WIN, IERROR

MPI_WIN_DETACH(WIN, BASE, IERROR)
     <type> BASE(*)
     INTEGER WIN, IERROR

⭐ Fortran 2008 Syntax ⭐

USE mpi_f08
MPI_Win_attach(win, base, size, ierror)
     TYPE(MPI_Win), INTENT(IN) :: win
     TYPE(*), DIMENSION(..), INTENT(IN) :: base
     INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: size
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

MPI_Win_detach(win, base, ierror)
     TYPE(MPI_Win), INTENT(IN) :: win
     TYPE(*), DIMENSION(..), INTENT(IN) :: base
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🌈 INPUT PARAMETERS 🌈

  • win β€” a window that was made with MPI_Win_create_dynamic πŸͺŸ (yes, that one specifically, no substitutions bestie)
  • base β€” the initial address of the window (it's a choice, choose wisely πŸ’)
  • size β€” size of the window, in bytes (nonnegative integer, so like, don't be negative about it πŸ’€)

πŸ’œ OUTPUT PARAMETERS πŸ’œ

  • win β€” window object returned by the call (handle) 🫢
  • ierror β€” Fortran only: the error status, as an integer ✨

πŸ‘‘ DESCRIPTION πŸ‘‘

okay so MPI_Win_attach is a one-sided MPI communication call, and what it does is attach a memory region to a window for RMA access. that region is size bytes long and starts at address base 🌸

the window win must have been created using MPI_Win_create_dynamic. multiple non-overlapping memory regions can be attached to the same dynamic window β€” that's totally fine, we love options πŸ’… but attaching overlapping memory regions to the same dynamic window? that's erroneous. not the vibe. don't do it 😭

if the base value you used with MPI_Win_attach was allocated by MPI_Alloc_mem, then the size of the window can be no larger than the value set by the MPI_Alloc_mem function. that's just the rules, no cap πŸŽ€

MPI_Win_detach can be used to detach a previously attached memory region from win. the memory address base and win must match the arguments you passed to a previous call to MPI_Win_attach β€” like, they have to be the same ones, no swapping πŸ¦‹


πŸ“ NOTES πŸ“

use memory allocated by MPI_Alloc_mem to guarantee properly aligned window boundaries β€” think word, double-word, cache line, page frame, and so on ⭐ aligned memory is the moment, trust.


πŸ’€ ERRORS πŸ’€

almost all MPI routines return an error value β€” C routines hand it back as the return result of the function, and Fortran routines put it in the last argument, periodt πŸ“Œ

before that error value gets returned, the current MPI error handler tied to the communication object (e.g., communicator, window, file) gets called. if there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and it'll call the associated MPI error handler 🫢

when MPI_COMM_SELF is not initialized β€” that's 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. and you can change that initial error handler:

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

if no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions, and the MPI_ERRORS_ABORT error handler is called for all other MPI functions. πŸ’…

Open MPI ships with three predefined error handlers you can use:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes 😭
  • 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 πŸŽ€

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

  • MPI_Comm_create_errhandler and then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler and then MPI_File_set_errhandler
  • MPI_Session_create_errhandler and then MPI_Session_set_errhandler β€” or at MPI_Session_init
  • MPI_Win_create_errhandler and then MPI_Win_set_errhandler
⚠️ note that MPI does not guarantee that an MPI program can continue past an error. so like… don't bank on it 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 πŸ“š


2003-2026, The Open MPI Community πŸ’–


and that's the whole page!! πŸŽ‰ this was MPI_WIN_ATTACH(3), dated Sep 10, 2026, from the Open MPI crew β€” go forth and attach your memory regions responsibly, bestie πŸ¦‹πŸ’…βœ¨

πŸ“¦ where this page comes from