MPI_FILE_SEEK_SHARED(3)

πŸ’… MPI_FILE_SEEK_SHARED(3) β€” Open MPI, bestie edition πŸŽ€

okay so this is MPI_File_seek_shared from Open MPI, and it's lowkey one of the most useful I/O calls you'll ever meet. Sit down, grab a strawberry drink πŸ“, we're moving the global shared file pointer together. As a group. Collectively. No cap.


✨ NAME ✨

MPI_File_seek_shared β€” updates the global shared file pointer (and it's collective, bestie, so nobody moves alone 🫢).


🌈 SYNTAX 🌈

πŸ’œ C Syntax

#include <mpi.h>

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

πŸ¦‹ Fortran Syntax

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

🌸 Fortran 2008 Syntax

USE mpi_f08
MPI_File_seek_shared(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, aka the handle to the file you're working with (it's a handle, periodt).
  • offset β€” the file offset, an integer. Yes it can be negative, we'll get there πŸ’….
  • whence β€” the update mode, an integer. This is the one that decides how the pointer moves, and the valid values are down in DESCRIPTION.

⭐ OUTPUT PARAMETER ⭐

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

πŸ”₯ DESCRIPTION πŸ”₯

So MPI_File_seek_shared updates the shared file pointer according to whence, and whence can be any of these little icons:

  • MPI_SEEK_SET β€” the pointer is set to offset.
  • MPI_SEEK_CUR β€” the pointer is set to the current pointer position plus offset.
  • MPI_SEEK_END β€” the pointer is set to the end of the file plus offset.

Now the important part, and I need you to hear me on this: MPI_File_seek_shared is collective. That means all the processes in the communicator group associated with the file handle fh have to call MPI_File_seek_shared with the same offset and same whence. All processes in the communicator group get synchronized before the shared file pointer is even updated. it's giving group project where everybody actually shows up for once πŸ˜­πŸ’–

The offset can be negative, which is how you seek backwards (rewind era πŸ•°οΈ). But heads up: it is erroneous to seek to a negative position in the view. 🚨

And the end of the view is defined to be the position of the next elementary data item, relative to the current view, following the last whole elementary data item accessible. ikyk what that means β€” it's literally the definition, keep it exact 🧚


πŸ’€ 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. bestie, that asymmetry is iconic and also mildly rude πŸ’…

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. no cap, that's the whole rule 🌈

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

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. yeah. everybody. πŸ’€
  • 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. (main character energy, honestly πŸ‘‘)
  • 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
⚠️ Note that MPI does not guarantee that an MPI program can continue past an error. like, fr fr, don't count on it surviving πŸ™ˆ

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


okay that's the whole page, you ate that πŸ“βœ¨ mwah πŸ’‹ β€” signed, sealed, and delivered by the Open MPI girlies, dated Sep 11, 2026, page MPI_FILE_SEEK_SHARED(3), version Open MPI. slay πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from