MPI_FILE_WRITE_ALL(3)

πŸ’– MPI_FILE_WRITE_ALL πŸ’–

okay so bestie 🫢 welcome to section 3 of the Open MPI manual. today's main character is MPI_FILE_WRITE_ALL, and yeah the title up top says MPI_FILE_WRITE_ALL(3), we're just folding that in here so the vibe stays cute. no cap, this one is lowkey iconic: it writes to a file, it's blocking, and it's collective. let's get into it πŸ’…


🌸 NAME 🌸

MPI_File_write_all β€” writes a file starting at the locations specified by individual file pointers. it's blocking, and it's collective. yes bestie, both. periodt.


✨ SYNTAX ✨

πŸŽ€ C Syntax πŸŽ€

#include <mpi.h>

int MPI_File_write_all(MPI_File fh, const void *buf,
     int count, MPI_Datatype datatype, MPI_Status *status)

πŸŽ€ Fortran Syntax πŸŽ€

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

πŸŽ€ Fortran 2008 Syntax πŸŽ€

USE mpi_f08
MPI_File_write_all(fh, buf, count, datatype, status, ierror)
     TYPE(MPI_File), INTENT(IN) :: fh
     TYPE(*), DIMENSION(..), INTENT(IN) :: buf
     INTEGER, INTENT(IN) :: count
     TYPE(MPI_Datatype), INTENT(IN) :: datatype
     TYPE(MPI_Status) :: status
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ“ INPUT PARAMETERS πŸ“

  • fh β€” the file handle. it's a handle, bestie. that's the whole thing. ✨
  • buf β€” the initial address of your buffer. it's a choice. (a "choice" type, if you know MPI-speak β€” iykyk 🧚)
  • count β€” how many elements you got in that buffer. an integer, obviously. πŸ”’
  • datatype β€” the data type of each buffer element. a handle. πŸ’œ

πŸ¦‹ OUTPUT PARAMETERS πŸ¦‹

  • status β€” the status object. it's a status, she's just standing there being a status. πŸ‘‘
  • ierror β€” Fortran only: the error status. an integer. 🌈

🌟 DESCRIPTION 🌟

okay so MPI_File_write_all is a collective routine that attempts to write into the file associated with fh β€” specifically at the current individual file pointer position, the one the system maintains for you, she's doing her own thing β€” a total number of count data items, and those items have datatype type, and they're coming from your buffer buf. the data gets written into those parts of the file specified by the current view. that's the whole deal. 🌸

MPI_File_write_all stores the number of datatype elements actually written in status. note the word actually β€” it's doing a lot of work there. every other field of status is undefined, so don't go poking around in there looking for extra info, bestie, there is none πŸ’€.

🚨 okay important: it is erroneous to call this function if MPI_MODE_SEQUENTIAL mode was specified when the file was opened. like, don't. that's a no from the standard. πŸ™ˆ

πŸ’€ ERRORS πŸ’€

almost all MPI routines return an error value β€” the C routines hand it back as the return result of the function, and the Fortran routines stick it in the last argument. classic.

before the error value comes back to you, the current MPI error handler associated with the communication object (so like a communicator, a window, a file β€” one of those) gets called. if no communication object is associated with the MPI call, then that call is considered attached to MPI_COMM_SELF and it'll call the associated MPI error handler. and when MPI_COMM_SELF is not initialized β€” i.e. before MPI_Init/MPI_Init_thread, or after MPI_Finalize, or when you're using the Sessions Model exclusively β€” the error raises the initial error handler. that one can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model, or by 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, and the MPI_ERRORS_ABORT error handler gets called for all other MPI functions. so like, know which one you're in. πŸ‘€

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 she's dramatic like that πŸ’…
  • 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 if MPI_Abort was called on that communicator. if it's called on a window or a file, it acts as if MPI_Abort was called on a communicator containing the group of processes in the corresponding window or file. and if it's called on a session, it aborts only the local process. so like, scope matters, bestie. πŸŽ€
  • MPI_ERRORS_RETURN β€” returns an error code to the application. the chill one. 🫢

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

  • MPI_Comm_create_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_Win_set_errhandler
⭐ note that MPI does not guarantee that an MPI program can continue past an error. that's just the rules, 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. πŸ“š


and that's the page, bestie!! πŸŽ€ huge thanks to The Open MPI Community πŸ’– β€” the copyright on this one runs 2003-2026, and this version is dated Sep 10, 2026, living under the Open MPI banner. go forth and write collectively, you ate. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from