MPI_FILE_SET_SIZE(3)

okay so bestie, welcome to MPI_FILE_SET_SIZE(3) from the Open MPI manual ✨ this is the file-resizing page, and yes it's collective, periodt. let's get into the lore 🫢

πŸ’– NAME πŸ’–

MPI_File_set_size β€” resizes a file (collective). like, the whole group has to agree, no solo main character energy πŸ’…

🧚 SYNTAX 🧚

🧸 C Syntax

          #include <mpi.h>

          int MPI_File_set_size(MPI_File fh, MPI_Offset size)

🧸 Fortran Syntax

          USE MPI
          ! or the older form: INCLUDE 'mpif.h'
          MPI_FILE_SET_SIZE(FH, SIZE, IERROR)
               INTEGER FH, IERROR
               INTEGER(KIND=MPI_OFFSET_KIND)   SIZE

🧸 Fortran 2008 Syntax

          USE mpi_f08
          MPI_File_set_size(fh, size, ierror)
               TYPE(MPI_File), INTENT(IN) :: fh
               INTEGER(KIND=MPI_OFFSET_KIND), INTENT(IN) :: size
               INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🌸 INPUT PARAMETERS 🌸

  • fh β€” file handle (handle). yes, it's giving handle, iykyk.
  • size β€” size to truncate or expand the file (integer).

πŸŽ€ OUTPUT PARAMETER πŸŽ€

  • ierror β€” Fortran only: error status (integer).

πŸ’œ DESCRIPTION πŸ’œ

okay so MPI_File_set_size resizes the file associated with the file handle fh, truncating UNIX files as necessary. it's collective, so all processes in the group must pass identical values for size β€” no cap, everybody has to agree 🫢.

when using MPI_File_set_size on a UNIX file, if size is larger than the current file size, the file size becomes size. if size is smaller than the current file size, the file is truncated at the position defined by size (from the beginning of the file and measured in bytes). regions of the file which have been previously written are unaffected. the written bits stay iconic, periodt ✨.

MPI_File_set_size does not affect the individual file pointers or the shared file pointer. not them, not today πŸ’….

note: the actual amount of storage space cannot be allocated by MPI_File_set_size. use MPI_File_preallocate to accomplish this. like, set_size is not the storage-allocator bestie.

also, it is erroneous to call this function if MPI_MODE_SEQUENTIAL mode was specified when the file was opened. that's a hard no β€” do not do it 😭.

πŸ”₯ ERRORS πŸ”₯

almost all MPI routines return an error value; C routines as the return result of the function and Fortran routines in the last argument. okay so here's the whole error-handler lore, bestie.

before the error value is returned, the current MPI error handler associated with the communication object (e.g., communicator, window, file) is called. if no communication object is associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. when MPI_COMM_SELF is not 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. the 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 info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple. if no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions and the MPI_ERRORS_ABORT error handler is called for all other MPI functions.

Open MPI includes three predefined error handlers that can be used:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes.
  • 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.

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, do not assume you can just keep going after an error, 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.

2003-2026, The Open MPI Community


and that's the vibe check, bestie 🫢 this page is from the Open MPI manual, MPI_FILE_SET_SIZE(3), dated Sep 11, 2026 β€” slay and stay iconic πŸ’…βœ¨

πŸ“¦ where this page comes from