MPI_FILE_CLOSE(3)

πŸ’– MPI_File_close πŸ’–

okay bestie, so this is a page from the Open MPI manual, and it's literally all about saying byeee to a file. yes, THE MPI_File_close β€” closes a file (collective). collective, meaning everybody's in on it, no sneaky solo exits. 🫢


✨ NAME ✨

MPI_File_close β€” Closes a file (collective). that's the whole vibe. πŸ“βœŒοΈ


✨ SYNTAX ✨

C Syntax 🌸

#include <mpi.h>

int MPI_File_close(MPI_File *fh)

Fortran Syntax 🌸

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_FILE_CLOSE(FH, IERROR)
     INTEGER FH, IERROR

Fortran 2008 Syntax 🌸

USE mpi_f08
MPI_File_close(fh, ierror)
     TYPE(MPI_File), INTENT(INOUT) :: fh
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

✨ INPUT/OUTPUT PARAMETER ✨

  • fh β€” the file handle, and it's a handle. it goes in AND out, it's giving bidirectional main character energy. πŸ’…

✨ OUTPUT PARAMETER ✨

  • ierror β€” Fortran only, bestie, C doesn't get one of these. it's the error status, and it's an integer. πŸ“

✨ DESCRIPTION ✨

okay so here's the tea β˜•: MPI_File_close first synchronizes file state, and then closes the file associated with fh. in that order. sync first, close second, no skipping steps.

and like, MPI_File_close is a collective routine. periodt. πŸŽ€

⚠️ real talk though: the user is responsible for making sure that all outstanding requests associated with fh have completed before calling MPI_File_close. that's on you, not on MPI. don't be out here closing files with requests still hanging, iykyk. 😭

✨ ERRORS ✨

ngl, almost every MPI routine returns an error value, and the way it comes back depends on your language:

  • C routines β†’ return it as the return result of the function
  • Fortran routines β†’ put it in the last argument

before that error value even gets returned, the current MPI error handler associated with the communication object (think communicator, window, file) gets called. πŸ¦‹

if there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF, and it'll call the associated MPI error handler. and when MPI_COMM_SELF isn't initialized (like before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when you're using the Sessions Model exclusively) the error raises the initial error handler. ✨

that initial error handler can be changed 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
  • the 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. that's just how it is. πŸ’€

Open MPI ships three predefined error handlers you can use, and they are:

  • MPI_ERRORS_ARE_FATAL β€” Causes the program to abort all connected MPI processes. dramatic much? yes. on purpose. πŸ”₯
  • 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, acts as if 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. πŸ’œ

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
🚨 bestie heads up: note that MPI does not guarantee that an MPI program can continue past an error. like, it might just be over. no cap.

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. πŸ“š


2003-2026, The Open MPI Community. protecting the brand since 2003, we love to see it. πŸ’–


and that's the whole page, bestie!! this one came straight out of the Open MPI docs, dated Sep 10, 2026, and it lives at page MPI_FILE_CLOSE(3). go forth and close your files responsibly, mwah πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from