MPI_Iscan(3)

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

πŸ’« MPI_Iscan(3) πŸ’«

okay bestie, welcome to the MPI manual, page MPI_Iscan(3) ✨ pull up a chair, grab a lil snack, we're doing nonblocking partial reductions today and honestly? it's giving iconic.


🌸 NAME 🌸

MPI_Iscan β€” computes the scan (partial reductions) of data on a collection of processes in a nonblocking way πŸ¦‹

like yes she does the prefix-reduction thing but she does it asynchronously, so you can go do your little side quests while she cooks. no cap.


✨ SYNOPSIS ✨

int MPI_Iscan(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
MPI_Request *request)
int MPI_Iscan_c(const void *sendbuf, void *recvbuf, MPI_Count count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
MPI_Request *request)

two flavors, same vibe πŸ’… the _c one is for when your count needs that big big MPI_Count energy.


πŸ“₯ INPUT PARAMETERS πŸ“₯

  • sendbuf β€” starting address of send buffer (choice). this is where your data starts, bestie 🫢
  • count β€” number of elements in input buffer (non-negative integer). non-negative! that's the rule, don't be chaotic.
  • datatype β€” data type of elements of input buffer (handle). MPI_Datatype moment πŸ’–
  • op β€” operation (handle). this is your MPI_Op, the lil function that knows how to combine stuff.
  • comm β€” communicator (handle). your group chat, basically. who's in the scan.

πŸ“€ OUTPUT PARAMETERS πŸ“€

  • recvbuf β€” starting address of receive buffer (choice). where the partial reductions land 🌈
  • request β€” communication request (handle). hold onto this, it's your receipt for the nonblocking operation πŸŽ€

🚨 NOTES ON COLLECTIVE OPERATIONS 🚨

the reduction functions (MPI_Op) do not return an error value. periodt. so if they detect a lil problem, all they can do is either call MPI_Abort or just silently skip it β€” like not addressing the group chat situation at all 😭

so lowkey, 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. it's not being shady on purpose, it just literally cannot tell you.

bestie the reason for this is the performance problems in ensuring that all collective routines return the same error value. so it's a trade-off, and yes it's a little cursed, but it's our little cursed. πŸ’€

🧡 THREAD AND INTERRUPT SAFETY 🧡

this routine is thread-safe πŸ‘‘ meaning you can safely use it from multiple threads with zero user-provided thread locks, no gatekeeping required. slay.

however β€” and this is the important part β€” the routine is not interrupt safe. typically this is because of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so don't be interrupting her mid-malloc, she will not recover gracefully fr fr.


🧚 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 they're invoked with the call statement. very vintage, very demure.

all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. yes, even the complicated ones. it's just integers all the way down πŸ“


πŸ’€ 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 that value comes back, the current MPI error handler gets called. by default, this error handler aborts the MPI job 😳 dramatic but effective.

the error handler may be changed with:

  • MPI_Comm_set_errhandler (for communicators)
  • MPI_File_set_errhandler (for files)
  • MPI_Win_set_errhandler (for RMA windows)

the MPI-1 routine MPI_Errhandler_set may be used but its use is deprecated β€” so like, she's still around but she's retired, we don't really call her anymore 🫠

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. resilient queen behavior ✨

here's the error code menu:

  • MPI_SUCCESS β€” No error; MPI routine completed successfully. πŸŽ‰ we love to see it.
  • MPI_ERR_ARG β€” Invalid argument. Some argument is invalid and is not identified by a specific error class (e.g., MPI_ERR_RANK). vague on purpose, sorry babe.
  • MPI_ERR_BUFFER β€” Invalid buffer pointer. Usually a null buffer where one is not valid. girl, you can't be passing NULL here 😭
  • MPI_ERR_COMM β€” Invalid communicator. A common error is to use a null communicator in a call (not even allowed in MPI_Comm_rank). so like, do not.
  • MPI_ERR_COUNT β€” Invalid count argument. Count arguments must be non-negative; a count of zero is often valid. zero is fine! negative is not!
  • 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. commit your types bestie, that's the whole thing πŸ’…
  • MPI_ERR_OTHER β€” Other error; use MPI_Error_string to get more information about this error code. the catch-all bin, but she'll tell you more if you ask nicely.

and that's the whole page!! go forth and nonblocking-scan, main character πŸ¦‹

anyway, this was page MPI_Iscan(3) from the MPI manual, dated 4/10/2026 β€” mwah, take care of her, she's a classic πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from