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 withMPI_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_errhandleronMPI_COMM_SELFwhen using the World model, or - via the
mpi_initial_errhandlerCLI argument tompiexec, 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 ifMPI_Abortwas called on that communicator. if called on a window or file, it acts as ifMPI_Abortwas 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_errhandlerand thenMPI_Comm_set_errhandlerMPI_File_create_errhandlerand thenMPI_File_set_errhandlerMPI_Session_create_errhandlerand thenMPI_Session_set_errhandlerβ or atMPI_Session_initMPI_Win_create_errhandlerand thenMPI_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 π
π Copyright π
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
- ubuntu stonking: openmpi-doc 5.0.10-6 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms