MPI_Exscan(3)

πŸ“¦
version 5.0.1 Β· 5 versions
, in nixos 26.05, ubuntu stonking

πŸ’– MPI_Exscan(3) β€” the "everyone before me but not me" scan πŸ’–

okay bestie, listen up, this is MPI_Exscan from the MPI manual, and it's genuinely one of the cutest collectives out there once you get it. no cap. πŸ¦‹


✨ NAME ✨

MPI_Exscan β€” computes the exclusive scan (aka partial reductions) of data on a collection of processes. yes babe, a whole collection. 🌸


πŸŽ€ SYNOPSIS πŸŽ€

int MPI_Exscan(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)

int MPI_Exscan_c(const void *sendbuf, void *recvbuf, MPI_Count count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)

two of them!! the _c one takes an MPI_Count for count instead of a plain int, in case you're being extra about big numbers πŸ’…


🌈 INPUT PARAMETERS 🌈

  • sendbuf β€” starting address of send buffer (choice). it's choice coded, do with that what you will 🫢
  • count β€” number of elements in input buffer (non-negative integer). non-negative, queen, so no negative vibes allowed πŸ’€
  • datatype β€” data type of elements of input buffer (handle)
  • op β€” operation (handle)
  • comm β€” intra-communicator (handle)

πŸ’œ OUTPUT PARAMETERS πŸ’œ

  • recvbuf β€” starting address of receive buffer (choice)

🧚 NOTES 🧚

so here's the whole vibe: MPI_Exscan is literally like MPI_Scan, EXCEPT β€” and this is the main character twist β€” the contribution from the calling process is not included in the result at the calling process. it is contributed to the subsequent processes, of course. πŸ™ˆ

it's giving "you did the work but your name isn't on the slide, the people after you get the credit." iconic. slightly tragic. slay either way. ✨


πŸ’… NOTES ON COLLECTIVE OPERATIONS πŸ’…

the reduction functions (MPI_Op) do not return an error value. like at all. zero. so if the functions detect an error, all they can do is either call MPI_Abort or silently skip the problem. 😭

so like β€” if you change the error handler from MPI_ERRORS_ARE_FATAL to something else, for example MPI_ERRORS_RETURN, then no error may be indicated. wild, I know. that's the risk you take.

the reason for this? performance problems in ensuring that all collective routines return the same error value. they simply could not make it work and be fast, so here we are. periodt.


πŸ¦‹ THREAD AND INTERRUPT SAFETY πŸ¦‹

this routine is thread-safe. it can be safely used by multiple threads without the need for any user-provided thread locks. go off, goroutines, go off πŸ‘‘

BUT. and it's a big but. it is not interrupt safe. typically this is due to the use of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so no Ctrl+C chaos mid-call, bestie πŸ’€


🌸 NOTES FOR FORTRAN 🌸

  • all MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is an integer and has the same meaning as the return value of the routine in C.
  • in Fortran, MPI routines are subroutines, and are invoked with the call statement.
  • all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran.

πŸ”₯ ERRORS πŸ”₯

all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value; C routines as the value of the function and Fortran routines in the last argument. before the value is returned, the current MPI error handler is called. by default, this error handler aborts the MPI job. 🚨

the error handler may be changed with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). the MPI-1 routine MPI_Errhandler_set may be used but its use is deprecated (we don't do that anymore babe). the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. note that MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. 🫢

  • MPI_SUCCESS β€” no error; MPI routine completed successfully. ✨ the dream.
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where one is not valid.
  • MPI_ERR_COMM β€” invalid communicator. a common error is to use a null communicator in a call (not even allowed in MPI_Comm_rank).
  • MPI_ERR_COUNT β€” invalid count argument. count arguments must be non-negative; a count of zero is often valid.
  • MPI_ERR_OP β€” invalid operation. MPI operations (objects of type MPI_Op) must either be one of the predefined operations (e.g., MPI_SUM) or created with MPI_Op_create.
  • MPI_ERR_TYPE β€” invalid datatype argument. additionally, this error can occur if an uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call.
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code.

fr fr bestie: check your datatype is committed, your count isn't negative, and your comm isn't null before you come crying to me. i love you but i will not be debugging that for you πŸ’–

okay that's the whole page!! this was MPI_Exscan(3) from the MPI manual, and the version/date stamp on this beauty is 4/10/2026. go forth and exclusive-scan responsibly, my little superstar πŸ‘‘βœ¨πŸŽ€

πŸ“¦ where this page comes from