MPI_WIN_LOCK(3)
π MPI_Win_lock β Open MPI, section 3 of the manual π
okay bestie, so this is the MPI_Win_lock page from the Open MPI man pages (section 3, iconic behavior) and we're gonna go through the whole thing together, every last flag, no skips, no vibe-based summarising. let's get into it π«Ά
MPI_Win_lock β starts an RMA access epoch that locks access to one particular rank. that's the whole glow-up in one line β¨
πΈ SYNTAX πΈ
C Syntax
#include <mpi.h>
int MPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win)
Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_WIN_LOCK(LOCK_TYPE, RANK, ASSERT, WIN, IERROR)
INTEGER LOCK_TYPE, RANK, ASSERT, WIN, IERROR
Fortran 2008 Syntax
USE mpi_f08
MPI_Win_lock(lock_type, rank, assert, win, ierror)
INTEGER, INTENT(IN) :: lock_type, rank, assert
TYPE(MPI_Win), INTENT(IN) :: win
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
lock_typeβ eitherMPI_LOCK_EXCLUSIVEorMPI_LOCK_SHARED(this one's a state, bestie, it changes the whole mood of the lock).rankβ the rank of the locked window. nonnegative integer, no negative energy allowed.assertβ a program assertion (integer).winβ the window object (handle).
π OUTPUT PARAMETER π
ierrorβ Fortran only: the error status (integer).
β¨ DESCRIPTION β¨
so it starts an RMA access epoch. and the way locks work is: they make sure that only the windows created by specific processes can be accessed by those processes β and by literally no other processes β during that epoch. exclusive little club, no plus-ones π
locks protect two things, and yes we're listing both:
- accesses to the locked target window that get effected by RMA calls issued between the lock call and the unlock call
- local load/store accesses to a locked local window that get executed between the lock call and the unlock call
now the rules of the club: accesses protected by an exclusive lock will not be concurrent at the window site with other accesses to that same window that are lock protected. accesses protected by a shared lock will not be concurrent at the window site with accesses protected by an exclusive lock to that same window. slay, but make it thread-safe π
the assert argument is there to give assertions about the context of the call, and those can be used for various optimizations. (peep Section 6.4.4 of the MPI-2 Standard for the full tea.) a value of assert = 0 is always valid β zero is the safe, unbothered, always-works option. the following assertion value is supported:
MPI_MODE_NOCHECK : No other processes will hold or attempt to acquire a conflicting lock while the caller holds the window lock. that's the promise you're making. keep it or the vibes are off π«Ά
π NOTES π
client/server environment check π¨ β in a setup where clients connect to a server and create windows that span both the client and the server, if a client or a server that has obtained a lock on such a window then terminates abnormally, the server or other clients may hang in an MPI_Win_lock call, failing to notice that the peer MPI job has terminated. so like. mourn the lost peer, but also, you might be stuck. π
π ERRORS π
almost all MPI routines return an error value, no cap β C routines hand it back as the return result of the function, and Fortran routines put it in the last argument.
before that error value comes back, the current MPI error handler associated with the communication object (think: communicator, window, file) gets called. and if there's no communication object associated with the MPI call? then the call is considered 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. you can change that initial error handler by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model, or via 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 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. periodt.
Open MPI includes three predefined error handlers that you can use:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. dramatic, but make it final πMPI_ERRORS_ABORTβ an error handler that can be invoked on a communicator, window, file, or session. when it's called on a communicator, it acts as ifMPI_Abortwas called on that communicator. if it's 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 it's called on a session, it aborts only the local process. very "know your audience" of it πMPI_ERRORS_RETURNβ returns an error code to the application. the polite one π
MPI applications can also implement their own error handlers, and the way you do that is by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
note that MPI does not guarantee that an MPI program can continue past an error. so like. don't just keep going and hope for the best, fr fr. π
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. iykyk π
See also:
MPI_Win_unlockMPI_Win_lock_all
π Copyright π
2003-2026, The Open MPI Community
and that's the whole page bestie, every parameter, every handler, every warning, all of it π this was MPI_WIN_LOCK(3) from Open MPI, dated Sep 10, 2026 β go forth, lock your windows, respect the epochs, and remember: assert = 0 is always valid and so are you π
β¨πΈ
π¦ 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