File Pointers and Offsets
In simple MPI-IO, each MPI process reads or writes a single block. We have three means of positioning where the read or write takes place for each process:
- MPI_File_seek/read – Use individual file pointers
- MPI_File_read_at – Calculate byte offsets
- MPI_File_seek_shared/read_shared – Access a shared file pointer
Techniques 1 and 2 are naturally associated with C and Fortran, respectively. In any case, the general goal is to associate successive segments of a file with processes of rank 0 through \(n - 1\), where \(n\) is the number of processes.
Calls to read or write functions must be preceded by a call to MPI_File_open. The following parameters are available to indicate how the file is to be opened. To combine multiple flags, use bitwise-or |
in C, or addition +
in Fortran.
MPI_MODE_RDONLY | read only |
MPI_MODE_WRONLY | write only |
MPI_MODE_RDWR | read and write |
MPI_MODE_CREATE | create file if it doesn't exist |
Note that a call to MPI_File_open defines both an individual file pointer for the process, and a shared file pointer for the communicator.
Reading by Using Individual File Pointers – C Code
Reading by Using Explicit Offsets – F90 Code