MPI_FILE_WRITE_SHARED(3)

πŸ’… MPI_FILE_WRITE_SHARED(3) β€” like, the Open MPI manual page, section 3, but make it make sense 🫢

okay bestie, so this is the Open MPI page for MPI_File_write_shared, and yes it's a whole mouthful but we're gonna get through it together. grab a lil snack πŸ“


✨ NAME ✨

MPI_File_write_shared β€” writes to a file using the shared file pointer. It's blocking, and it's noncollective. that's the whole vibe. πŸ’–


🌈 SYNTAX 🌈

πŸ’œ C Syntax

#include <mpi.h>

int MPI_File_write_shared(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_SHARED(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_shared(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/OUTPUT PARAMETER πŸ”„

  • fh β€” the file handle, bestie. it's a handle. (the file one, not the lil "handle this" one 😭)

πŸ“₯ INPUT PARAMETERS πŸ“₯

  • buf β€” the initial address of your buffer. it's a choice, so pick one, we love options ✨
  • count β€” how many elements are chillin' in that buffer (integer, no decimals, don't try it)
  • datatype β€” the data type of each element in the buffer (handle). yes every single element has one, consistent queen πŸ‘‘

πŸ“€ OUTPUT PARAMETERS πŸ“€

  • status β€” the status object. it's giving "here's what happened" (status)
  • ierror β€” Fortran only: the error status (integer). C girlies, you get your error as the return value instead πŸ’…

πŸ—£οΈ DESCRIPTION πŸ—£οΈ

so. MPI_File_write_shared is a blocking routine that writes files using the shared file pointer. that's the entire plot.

but here's the tea β˜• β€” because this is a noncollective routine, the order of serialization is not deterministic. like, at all. nobody can promise you who writes first. it's giving group chat at 2am, everyone typing at once, nobody knowing whose message lands where 😭


πŸ’€ ERRORS πŸ’€

okay so, literally almost every MPI routine returns an error value. C routines hand it back as the return result of the function, and Fortran routines tuck it into the last argument. classic.

before that error value comes back home, the current MPI error handler associated with the communication object (think: communicator, window, file) gets called. and if there's no communication object associated with the MPI call? then the call is considered attached to MPI_COMM_SELF and calls the associated MPI error handler. yep.

when MPI_COMM_SELF isn't 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. and you can change that initial error handler:

  • 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
  • an info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple.

and if no other appropriate error handler has been set? then MPI_ERRORS_RETURN gets called for MPI I/O functions, and MPI_ERRORS_ABORT gets called for all other MPI functions. slay, consistent.

Open MPI includes three predefined error handlers you can use, and yes we're listing all three:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic, but make it fatal πŸ’€
  • 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 was called on that communicator. if called on a window or 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 called on a session, it aborts only the local process. context is everything bestie ✨
  • MPI_ERRORS_RETURN β€” returns an error code to the application. polite. respectful. πŸŽ€

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. like, it genuinely might just not. no cap.

see the MPI man page for a full list of MPI error codes, and the Error Handling section of the MPI-3.1 standard for more info. iykyk πŸ“š


2003-2026, The Open MPI Community


and that's the whole page, bestie 🧚✨ β€” brought to you by the Open MPI girlies, MPI_FILE_WRITE_SHARED(3), dated Sep 11, 2026. go forth and write those files, shared-pointer style. periodt πŸ’…πŸŒΈ

πŸ“¦ where this page comes from