MPI_FETCH_AND_OP(3)
πΈ NAME πΈ
MPI_Fetch_and_op β bestie, it takes the contents of the origin buffer, combines them with a target buffer, and hands you back what the target buffer had before. iconic behavior honestly π
β¨ SYNTAX β¨
π C Syntax
#include <mpi.h>
int MPI_Fetch_and_op(const void *origin_addr, void *result_addr,
MPI_Datatype datatype, int target_rank, MPI_Aint target_disp,
MPI_Op op, MPI_Win win)
π Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_FETCH_AND_OP(ORIGIN_ADDR, RESULT_ADDR, DATATYPE, TARGET_RANK,
TARGET_DISP, OP, WIN, IERROR)
<type> ORIGIN_ADDR, RESULT_ADDR(*)
INTEGER(KIND=MPI_ADDRESS_KIND) TARGET_DISP
INTEGER DATATYPE, TARGET_RANK, OP, WIN, IERROR
π Fortran 2008 Syntax
USE mpi_f08
MPI_Fetch_and_op(origin_addr, result_addr, datatype, target_rank,
target_disp, op, win, ierror)
TYPE(*), DIMENSION(..), INTENT(IN) :: origin_addr
TYPE(*), DIMENSION(..) :: result_addr
TYPE(MPI_Datatype), INTENT(IN) :: datatype
INTEGER, INTENT(IN) :: target_rank
INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: target_disp
TYPE(MPI_Op), INTENET(IN) :: op
TYPE(MPI_Win), INTENT(IN) :: win
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
origin_addrβ the starting address of the buffer, no cap. (choice)result_addrβ the starting address of the result buffer, that's where the tea gets collected. (choice)datatypeβ the data type of the entry living in the origin, result, and target buffers. (handle)target_rankβ rank of the target, has to be a nonnegative integer. (nonnegative integer)target_dispβ displacement from the start of the window to the beginning of the target buffer. (nonnegative integer)opβ the reduce operation. (handle)winβ the window object. (handle)
π OUTPUT PARAMETER π
ierrorβ Fortran only: error status. (integer)
π¦ DESCRIPTION π¦
Okay so here's the vibe: it accumulates one element of type datatype, going from the origin buffer (origin_addr) over to the buffer at offset target_disp, inside the target window that target_rank and win are pointing at. It uses operation op, and then β this is the fun part β it returns into the result buffer result_addr whatever the target buffer was holding before the accumulation happened. like, it's giving receipts πΈ
The origin and result buffers (origin_addr and result_addr) must be disjoint. Not optional, not negotiable, fr fr. Any of the predefined operations for MPI_Rreduce can go in as op, plus MPI_NO_OP or MPI_REPLACE β but user-defined functions? nope, can't use those. The datatype argument has to be a predefined datatype. And the whole operation is executed atomically. periodt.
There's a new predefined operation, MPI_REPLACE. It corresponds to the associative function f(a, b) =b β meaning the current value sitting in the target memory just gets replaced by the value the origin supplied. out with the old π
And there's another new predefined operation, MPI_NO_OP. It corresponds to the associative function f(a, b) = a β so the current value in the target memory gets returned in the result buffer over at the origin, and nothing at all happens to the target buffer. zero changes, zero drama, main character energy of doing nothing π§
π NOTES π
It is the user's responsibility to guarantee that, when using the accumulate functions, the target displacement argument is such that accesses to the window are properly aligned according to the data type arguments in the call to the MPI_Fetch_and_op function.
that's on you bestie, not on MPI β¨
π ERRORS π
Almost all MPI routines return an error value β C routines give it back as the return result of the function, and Fortran routines put it in the last argument. classic.
Before that error value comes back, the current MPI error handler associated with the communication object (like a communicator, window, or 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 it'll call the associated MPI error handler. And when MPI_COMM_SELF isn't initialized (i.e., 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 with 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 gets called for MPI I/O functions, while the MPI_ERRORS_ABORT error handler gets called for all other MPI functions. π
Open MPI ships three predefined error handlers you can use:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. yeah. all of them. π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.MPI_ERRORS_RETURNβ returns an error code to the application. polite of it π«Ά
MPI applications can also implement their own error handlers, 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, be careful 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_Get_accumulateMPI_Reduce
π Copyright π
2003-2026, The Open MPI Community
and that's the whole page, bestie β Open MPI, page MPI_FETCH_AND_OP(3), dated Sep 10, 2026. slay, go accumulate something atomically, ily ππΈβ¨
π¦ 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