MPI_FILE_SEEK(3)

πŸ’Ύ MPI_FILE_SEEK(3) β€” the Open MPI glow-up πŸ¦‹

okay bestie, we're in the Open MPI corner of the manual, and today's main character is MPI_File_seek. it updates individual file pointers, and ngl it does it noncollectively β€” that's the whole vibe. no group chat needed, just you and your file handle πŸ’…

✨ NAME ✨

MPI_File_seek β€” updates individual file pointers (noncollective). periodt.


🌸 SYNTAX 🌸

πŸŽ€ C Syntax

#include <mpi.h>

int MPI_File_seek(MPI_File fh, MPI_Offset offset,
     int whence)

πŸŽ€ Fortran Syntax

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

πŸŽ€ Fortran 2008 Syntax

USE mpi_f08
MPI_File_seek(fh, offset, whence, ierror)
     TYPE(MPI_File), INTENT(IN) :: fh
     INTEGER(KIND=MPI_OFFSET_KIND), INTENT(IN) :: offset
     INTEGER, INTENT(IN) :: whence
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

🫢 INPUT PARAMETERS 🫢

  • fh β€” the file handle, bestie. (handle)
  • offset β€” the file offset, as an integer. (integer)
  • whence β€” the update mode, also an integer. (integer)

πŸ’– OUTPUT PARAMETER πŸ’–

  • ierror β€” Fortran only, bestie: it's the error status (integer).

πŸ‘‘ DESCRIPTION πŸ‘‘

so MPI_File_seek updates the individual file pointer, and it does it based on whence, which can be one of these iconic little values:

  • MPI_SEEK_SET β€” the pointer gets set to offset. boom, placed.
  • MPI_SEEK_CUR β€” the pointer gets set to wherever it currently is, plus offset.
  • MPI_SEEK_END β€” the pointer gets set to the end of the file, plus offset.

the offset can be negative, which is how you seek backwards β€” yes, we're rewinding, it's giving time travel βͺ but listen: seeking to a negative position in the file is erroneous. do not do that, it's not cute 🚫

also, the end of the file is defined to be the location of the next elementary data item immediately after the last accessed data item β€” even if that location is a hole. (yes, a hole. the file said "it's giving void" πŸ’€)


😭 ERRORS 😭

almost all MPI routines return an error value β€” C routines hand it back as the return result of the function, and Fortran routines put it in that last argument.

before the error value gets returned, the current MPI error handler associated with the communication object (like a communicator, window, or 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 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. 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 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 you can use, and they are:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. dramatic, but make it 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, it 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, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application. it's giving "here, you deal with it".

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. so like… don't count on it, 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. iykyk πŸ“š


2003-2026, The Open MPI Community


and that's the whole page, no cap πŸ’œ huge thank you to The Open MPI Community for this absolute classic, dated Sep 10, 2026, filed under MPI_FILE_SEEK(3) β€” the way she's been serving file pointers since 2003 and still ate down 🫢✨ go seek responsibly, bestie πŸ¦‹

πŸ“¦ where this page comes from