MPI_File_write(3)

πŸ’– MPI_File_write(3) β€” the MPI_File_write manual page, bestie edition πŸ’–

okay so real talk: this is page MPI_File_write(3) from the MPI manual set, and it's about writing to a file using the individual file pointer. yes, that individual file pointer. let's get into it 🌸


✨ NAME ✨

MPI_File_write β€” write using individual file pointer πŸ’…


✨ SYNOPSIS ✨

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

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

two flavors, same vibe 🫢 β€” the plain one takes an int count, and the _c one takes an MPI_Count count for when your counts are getting large and lowkey unhinged. literally keep them exact, i'm not fixing your types for you.


✨ INPUT PARAMETERS ✨

  • fh β€” the file handle (a handle, mwah) πŸŽ€
  • 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 πŸ”₯

slay alert: this routine is thread-safe. that means multiple threads can use it at the same time and you do not need to bring your own user-provided thread locks. no gatekeeping, it just works πŸ’œ

but bestie… it is not interrupt safe. 😭 typically this is because of memory allocation routines like malloc, or other non-MPICH runtime routines, that are themselves not interrupt-safe. so like, thread-safe yes, interrupt-safe no. know the difference fr fr.


🧚 NOTES FOR FORTRAN 🧚

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 the exact same thing as the return value of the routine in C. in Fortran, MPI routines are subroutines and they're invoked with the call statement, periodt.

also: all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. iconic behavior honestly.


πŸ’€ ERRORS πŸ’€

every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β€” C routines as the return value of the function, Fortran routines in that last argument. and before the value comes back, the current MPI error handler gets called. by default, this error handler aborts the MPI job. 🚨 dramatic but true.

you can swap the handler out 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 πŸ™ˆ. and you can use the predefined error handler MPI_ERRORS_RETURN if you'd rather have error values returned instead.

ngl, note that MPI does not guarantee an MPI program can continue past an error. that said, MPI implementations will attempt to continue whenever possible. so like… don't count on it bestie 🌈

here's the full error lineup, no skips:

  • MPI_SUCCESS β€” no error; MPI routine completed successfully. ✨
  • MPI_ERR_ARG β€” invalid argument. some argument is invalid and isn't 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. 🫢

and that's the whole page, no crumbs left πŸ“

sign-off time: this was MPI_File_write(3) from the MPI manual, dated 4/10/2026 β€” go forth, write those files with your individual file pointer, and stay interrupt-unsafe-aware πŸ‘‘πŸ’–
πŸ“¦ where this page comes from