MPI_CANCEL(3)
π MPI_CANCEL π
okay bestie, welcome to the Open MPI manual for MPI_Cancel β she's lowkey a legend and you're about to understand her perfectly, no cap π«Ά
πΈ NAME πΈ
MPI_Cancel β cancels a communication request. that's it, that's the whole vibe β¨
π SYNTAX π
β¨ C Syntax
#include <mpi.h>
int MPI_Cancel(MPI_Request *request)
β¨ Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_CANCEL(REQUEST, IERROR)
INTEGER REQUEST, IERROR
β¨ Fortran 2008 Syntax
USE mpi_f08
MPI_Cancel(request, ierror)
TYPE(MPI_Request), INTENT(IN) :: request
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETER π
requestβ the communication request (that's a handle, bestie π).
π¦ OUTPUT PARAMETER π¦
ierrorβ Fortran only: the error status (an integer, nothing fancy).
π DESCRIPTION π
so MPI_Cancel is the operation that lets you cancel pending communications. and like β this is genuinely required for cleanup, not just a cute-to-have. posting a send or a receive ties up your user resources (your send buffers, your receive buffers), and a cancel might be exactly what you need to free those resources gracefully instead of letting them haunt you π
a call to MPI_Cancel marks a pending, nonblocking communication operation (send or receive) for cancellation. crucial detail: the cancel call is local. it returns immediately β possibly before the communication is actually canceled, so don't get it twisted π. and it is still necessary to complete a communication that has been marked for cancellation, using a call to MPI_Request_free, MPI_Wait, or MPI_Test (or any of the derived operations). like, you marked it, you still gotta see it through, periodt π
now here's the slay part: if a communication is marked for cancellation, then an MPI_Wait call for that communication is guaranteed to return, irrespective of the activities of other processes (i.e., MPI_Wait behaves as a local function). similarly, if MPI_Test is repeatedly called in a busy wait loop for a canceled communication, then MPI_Test will eventually be successful. that's the icon behavior we love β¨
MPI_Cancel can also be used to cancel a communication that uses a persistent request (see Section 3.9 in the MPI Standard, βPersistent Communication Requestsβ) in the same way it is used for nonpersistent requests. a successful cancellation cancels the active communication, but not the request itself β read that again, bestie. after the call to MPI_Cancel and the subsequent call to MPI_Wait or MPI_Test, the request becomes inactive and can be activated for a new communication. recycling era π
the successful cancellation of a buffered send frees the buffer space occupied by the pending message. free real estate π
okay and this next bit is the whole main-character rule of the function: either the cancellation succeeds or the communication succeeds, but not both. not both!! π«Ά
- if a send is marked for cancellation, then it must be the case that either the send completes normally β in which case the message sent is received at the destination process β or that the send is successfully canceled, in which case no part of the message is received at the destination. then, any matching receive has to be satisfied by another send. iykyk π
- if a receive is marked for cancellation, then it must be the case that either the receive completes normally, or that the receive is successfully canceled, in which case no part of the receive buffer is altered. then, any matching send has to be satisfied by another receive.
and if the operation has been canceled, then information to that effect will be returned in the status argument of the operation that completes the communication. so check your status, she's telling you things π
π NOTES π
the primary expected use of MPI_Cancel is in multi-buffering schemes, where speculative MPI_Irecvs are made. when the computation completes, some of these requests may remain β and using MPI_Cancel lets you cancel these unsatisfied requests. literally built for the "oops i over-posted" moment π
π₯ ERRORS π₯
almost all MPI routines return an error value β C routines as the return result of the function, and Fortran routines in the last argument. classic π
before the 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. the 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.
Open MPI includes three predefined error handlers that can be used:
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 called on a communicator, it acts as ifMPI_Abortwas called on that communicator. if called on a window or file, acts as ifMPI_Abortwas 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.MPI_ERRORS_RETURNβ returns an error code to the application. the gentle one π«Ά
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. like, no promises 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_Probe
π COPYRIGHT π
2003-2026, The Open MPI Community
and that's the whole page, bestie β slay π
β¨ this was the MPI_CANCEL(3) page from the Open MPI manual, dated Sep 11, 2026, brought to you by the 2003-2026 Open MPI Community. go forth and cancel responsibly ππ¦
π¦ where this page comes from
- arch rolling: openmpi 5.0.11-1 Β· BSD-3-Clause AND LicenseRef-MPICH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms