MPI_FILE_IWRITE(3)

πŸ’– MPI_FILE_IWRITE πŸ’–

okay bestie, so this is MPI_File_iwrite(3) from the Open MPI manual, and no cap, it's giving "write to a file but make it async" πŸ’… let me put you on 🫢


✨ NAME ✨

MPI_File_iwrite β€” writes a file starting at the location specified by the individual file pointer. She's nonblocking and noncollective, periodt πŸ’–


🌸 SYNTAX 🌸

πŸŽ€ C Syntax

#include <mpi.h>

int MPI_File_iwrite(MPI_File fh, const void *buf, int count,
     MPI_Datatype datatype, MPI_Request *request)

πŸŽ€ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_FILE_IWRITE(FH, BUF, COUNT, DATATYPE, REQUEST, IERROR)
     <type>  BUF(*)
     INTEGER FH, COUNT, DATATYPE, REQUEST, IERROR

πŸŽ€ Fortran 2008 Syntax

USE mpi_f08
MPI_File_iwrite(fh, buf, count, datatype, request, ierror)
     TYPE(MPI_File), INTENT(IN) :: fh
     TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: buf
     INTEGER, INTENT(IN) :: count
     TYPE(MPI_Datatype), INTENT(IN) :: datatype
     TYPE(MPI_Request), INTENT(OUT) :: request
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🌈 INPUT/OUTPUT PARAMETER 🌈

  • fh β€” file handle (handle). it's literally the vibe of your file, the main character identifier πŸ’«

πŸ¦‹ INPUT PARAMETERS πŸ¦‹

  • buf β€” initial address of buffer (choice). this is the tea you're writing, the starting address of it anyway πŸ“
  • count β€” number of elements in buffer (integer). how many lil guys we're writing, count them, don't skip ✨
  • datatype β€” data type of each buffer element (handle). what kind of element each one is πŸ’œ

πŸ‘‘ OUTPUT PARAMETER πŸ‘‘

  • request β€” request object (handle). the lil ticket you hold onto so you can check on your write later, iconic πŸ”₯
  • ierror β€” Fortran only: error status (integer). Fortran girlies get their errors in the last argument, that's just the rules πŸ’…

πŸ’… DESCRIPTION πŸ’…

So MPI_File_iwrite is the nonblocking version of the MPI_File_write (see mpi-file-write) interface. bestie it's the same energy, she just doesn't wait around for you 😌

She attempts to write into the file associated with fh β€” and lowkey important β€” she writes at the current individual file pointer position maintained by the system. So that pointer is doing its own thing, the system is keeping track, you're not passing an offset, that's the whole bit πŸŽ€

She writes a total number of count data items, having datatype type, from the user's buffer buf. The data gets written into those parts of the file specified by the current view. Yes, the view matters. Everything is the view. periodt πŸ¦‹

MPI_File_iwrite stores the number of datatype elements actually written in status. And note β€” ngk β€” all other fields of status are undefined. So don't go reading the rest of it and acting surprised, she told you πŸ’€

⚠️ okay this one's important: it is erroneous to call this function if MPI_MODE_SEQUENTIAL mode was specified when the file was open. like, don't. fr fr. that's a you problem if you do πŸ™ˆ

πŸ’€ 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. that's just how MPI does, iykyk ✨

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 (see mpi-init) / MPI_Init_thread (see mpi-init-thread), after MPI_Finalize (see 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 (see 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 (see mpi-comm-spawn) / MPI_Comm_spawn_multiple (see 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. that's the split, slay πŸ’…

Open MPI includes three predefined error handlers that can be used:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic much? yes. iconic? also yes 😭
  • 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 (see mpi-abort) was called on that communicator. If called on a window or file, acts as if MPI_Abort (see 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. πŸŽ€
  • MPI_ERRORS_RETURN β€” returns an error code to the application. the chill one. she just hands you the code and lets you deal πŸ“

MPI applications can also implement their own error handlers by calling:

  • MPI_Comm_create_errhandler (see mpi-comm-create-errhandler) then MPI_Comm_set_errhandler (see mpi-comm-set-errhandler)
  • MPI_File_create_errhandler (see mpi-file-create-errhandler) then MPI_File_set_errhandler (see mpi-file-set-errhandler)
  • MPI_Session_create_errhandler (see mpi-session-create-errhandler) then MPI_Session_set_errhandler (see mpi-session-set-errhandler) or at MPI_Session_init (see mpi-session-init)
  • MPI_Win_create_errhandler (see mpi-win-create-errhandler) then MPI_Win_set_errhandler (see mpi-win-set-errhandler)
⚠️ note that MPI does not guarantee that an MPI program can continue past an error. like, she might just be done. no promises. πŸ’€

See the MPI man page (see open-mpi) for a full list of MPI error codes (see open-mpi-errors) πŸ“œ

See the Error Handling section of the MPI-3.1 standard for more information. 🌈


Copyright 2003-2026, The Open MPI Community


okay that's the whole page bestie, you ate that reading it whole πŸ’… Open MPI, copyright 2003-2026 The Open MPI Community, and this lil drop is dated Sep 10, 2026 β€” go write some files nonblocking, you got this 🫢✨

πŸ“¦ where this page comes from