MPI_File_read_at(3)
β¨ MPI_File_read_at β bestie, we're reading at an EXPLICIT offset β¨
okay so this one lives in the MPI manual (yes, that MPI, the message-passing icon), and it's about grabbing data out of a file at a spot you pick. no hidden file pointer drama. we love a decisive queen. π
πΈ NAME πΈ
MPI_File_read_at β Read using explicit offset. that's the whole vibe. you say where, it reads from there. periodt.
π¦ SYNOPSIS π¦
int MPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,
MPI_Datatype datatype, MPI_Status *status)
int MPI_File_read_at_c(MPI_File fh, MPI_Offset offset, void *buf,
MPI_Count count, MPI_Datatype datatype,
MPI_Status *status)
two versions bestie!! the classic one with a plain int count, and the _c glow-up where count is an MPI_Count instead. slay. π
π INPUT PARAMETERS π
fhβ the file handle (a handle, so it's giving "you already opened this, right?" energy).offsetβ the file offset (an integer). this is your call, no auto-advancing, no surprises. iconic.countβ how many elements are in the buffer (an integer).datatypeβ the datatype of each buffer element (a handle).
π OUTPUT PARAMETERS π
bufβ initial address of buffer (choice). yes bestie it's under output here, don't @ me, that's what the page says. π«Άstatusβ the status object (Status).
π₯ THREAD AND INTERRUPT SAFETY π₯
good news first: this routine is thread-safe. that means multiple threads can use it at the same time, no cap, and you do not need to bring your own user-provided thread locks. she handles herself. π
but β and this is the part where I grab your hand β it is not interrupt safe. the reason is typically that it uses memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so like. threads: yes. interrupts: absolutely not. π
π NOTES FOR FORTRAN π
- Every MPI routine in Fortran (except for
MPI_WTIMEandMPI_WTICK) gets an extra argument calledierrtacked onto the end of the argument list.ierris an integer and it means exactly the same thing as the return value of the routine in C. - In Fortran, MPI routines are subroutines and they get invoked with the
callstatement. very retro, very chic. - All MPI objects (e.g.,
MPI_Datatype,MPI_Comm) are of typeINTEGERin Fortran.
π ERRORS π
so all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value β C routines hand it back as the value of the function, Fortran routines put it in that last argument. and before that value comes back to you, the current MPI error handler gets called. by default, that error handler aborts the MPI job. like, full stop, everybody out. π
you can swap the error handler with:
MPI_Comm_set_errhandlerβ for communicatorsMPI_File_set_errhandlerβ for filesMPI_Win_set_errhandlerβ for RMA windows
the MPI-1 routine MPI_Errhandler_set may also be used, but its use is deprecated β so like, it's giving "we don't do that anymore bestie."
if you want error values returned instead of the job getting nuked, use the predefined error handler MPI_ERRORS_RETURN. β¨
heads up: MPI does not guarantee that an MPI program can continue past an error. however, MPI implementations will attempt to continue whenever possible. so it might be fine. it might not. vibe check accordingly.
now the error codes themselves:
MPI_SUCCESSβ no error; the MPI routine completed successfully. we love a clean run. πMPI_ERR_ARGβ invalid argument. some argument is invalid and it 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 uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call.MPI_ERR_OTHERβ other error; useMPI_Error_stringto get more information about this error code.
that's the whole page bestie, every flag, every error, every Fortran footnote, nothing skipped, no crumbs left behind π
sign-off time: this little masterpiece is dated 4/10/2026, it belongs to the MPI collection, and you'd find it filed under MPI_File_read_at(3) β so go read at an explicit offset, stay thread-safe, and do NOT get interrupted. mwah. ππ¦β¨
π¦ where this page comes from
- nixos 26.05: mpich 5.0.1
- ubuntu stonking: mpich-doc 5.0.1-9 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms