MPI_File_write_shared(3)

πŸ’– NAME πŸ’–

MPI_File_write_shared β€” bestie, it writes using the shared file pointer ✨


🌸 SYNOPSIS 🌸

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

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

like yes, two of them. the _c one is the cool cousin with the MPI_Count count πŸ’…


✨ INPUT PARAMETERS ✨

  • fh β€” file handle (handle). it's giving "which file are we even writing to" πŸŽ€
  • buf β€” initial address of buffer (choice)
  • count β€” number of elements in buffer (integer)
  • datatype β€” datatype of each buffer element (handle)

πŸ¦‹ OUTPUT PARAMETERS πŸ¦‹

  • status β€” status object (Status)

🫢 THREAD AND INTERRUPT SAFETY 🫢

okay so the good news: this routine is thread-safe. literally means you can use it from multiple threads without bringing your own thread locks, no cap. slay. πŸ‘‘

the not-so-good news: it is not interrupt safe. and why? typically because of memory allocation routines like malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, the vibe check fails on interrupts specifically. 😭


🌈 NOTES FOR FORTRAN 🌈

Fr fr, all MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) get an extra argument ierr tacked onto the end of the argument list. ierr is an integer and it means exactly the same thing as the return value of the routine in C. and in Fortran, MPI routines are subroutines, invoked with the call statement. periodt.

also: all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. remember it. iykyk πŸ’œ


πŸ’€ ERRORS πŸ’€

so 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 that last argument. before the value comes back, the current MPI error handler gets called. by default, this error handler aborts the MPI job. like, the whole thing. πŸ’€

you can change the error handler 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 β€” like, it's still there, but we don't talk about it πŸ™ˆ

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. 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).
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where one is not valid.
  • MPI_ERR_COUNT β€” invalid count argument. count arguments must be non-negative; a count of zero is often valid.
  • 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.

ok that's the whole page bestie, go forth and write to that shared file pointer πŸ“πŸ§š

signing off ✨ this was the MPI manual page for MPI_File_write_shared(3), dated 4/10/2026 β€” mwah, take care of her πŸ’–πŸŽ€

πŸ“¦ where this page comes from