MPI_WIN_SHARED_QUERY(3)

πŸ’… MPI_Win_shared_query β€” Query a shared memory window

okay bestie, welcome to the MPI_WIN_SHARED_QUERY(3) page from the Open MPI manual β€” yes that's the manual name, consider it folded in and slayed ✨ This is the whole thing, every crumb, no cap.


✨ SYNTAX ✨

🌸 C Syntax

#include <mpi.h>

int MPI_Win_shared_query (MPI_Win win, int rank, MPI_Aint *size,
                          int *disp_unit, void *baseptr)

πŸŽ€ Fortran Syntax

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

πŸ¦‹ Fortran 2008 Syntax

USE mpi_f08
MPI_Win_shared_query(win, rank, size, disp_unit, baseptr, ierror)
     USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
     TYPE(MPI_Win), INTENT(IN) :: win
     INTEGER, INTENT(IN) :: rank
     INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(OUT) :: size
     INTEGER, INTENT(OUT) :: disp_unit
     TYPE(C_PTR), INTENT(OUT) :: baseptr
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ’– INPUT PARAMETERS πŸ’–

  • win β€” your shared memory window object (it's a handle, bestie β€” hold it gently 🫢).
  • rank β€” the rank inside the group of window win, and it's a non-negative integer β€” OR MPI_PROC_NULL. those are your two moods, pick one πŸ’….

⭐ OUTPUT PARAMETERS ⭐

  • size β€” how big the window segment is (a non-negative integer, she's giving measurements πŸ“).
  • disp_unit β€” the local unit size for displacements, in bytes (a positive integer β€” bytes, always bytes).
  • baseptr β€” the address you use for load/store access to that window segment (it's a choice, literally).
  • ierror β€” Fortran girlies only: error status, and yes it's an integer πŸ’€.

🌈 DESCRIPTION 🌈

so MPI_Win_shared_query queries the process-local address for remote memory segments that were created with MPI_Win_allocate_shared. And here's the iconic plot twist: this function can totally return different process-local addresses for the same physical memory on different processes. yes, same memory, different addresses, main character energy on every rank πŸ‘‘

The memory it hands you back can be used for load/store accesses β€” but only subject to the constraints defined in MPI-3.1 section 11.7. read that section, i'm begging 😭

Also: this function can only be called with windows of flavor MPI_WIN_FLAVOR_SHARED. If the window you passed isn't that flavor, the error MPI_ERR_RMA_FLAVOR gets raised. wrong vibe detected, call rejected πŸ’€

And when rank is MPI_PROC_NULL, the pointer, disp_unit, and size you get back are the pointer, disp_unit, and size of the memory segment belonging to the lowest rank that specified size > 0 β€” like, she goes looking for the first rank that actually brought something to the group chat.

And if all the processes in the group attached to the window specified size = 0? Then the call returns size = 0 and a baseptr as if MPI_Alloc_mem was called with size = 0. empty window, empty vibes, still valid 🫠


🧚 C NOTES 🧚

The parameter baseptr is of type void * so that you can pass any pointer object for it. The argument you provide should be a pointer to a pointer of arbitrary type (e.g. void **). double pointer, double the fun, iykyk ✨


πŸ’€ 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. classic.

Before that error value is returned, the current MPI error handler associated with the communication object (e.g., communicator, window, file) is called. If no communication object is associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. When MPI_COMM_SELF is not initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when 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 using the World model, or the mpi_initial_errhandler CLI argument to mpiexec, or 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. okay? okay 🫢

Open MPI includes three predefined error handlers you can use β€” lineup time:

  • MPI_ERRORS_ARE_FATAL β€” Causes the program to abort all connected MPI processes. everyone's leaving the party, no survivors πŸ’€
  • 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, 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, aborts only the local process. context-aware chaos, honestly iconic.
  • MPI_ERRORS_RETURN β€” Returns an error code to the application. the polite one. she just tells you and lets you deal πŸ™ˆ

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. like, fr fr, don't assume you can just keep going after one.

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_Win_allocate_shared

2003-2026, The Open MPI Community


and that's the whole page bestie, go forth and share your memory safely πŸ’œβœ¨

kisses from the Open MPI girlies β€” this was MPI_WIN_SHARED_QUERY(3), dated Sep 11, 2026, mwah πŸŽ€

πŸ“¦ where this page comes from