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:

  1. MPI_File_seek/read – Use individual file pointers
  2. MPI_File_read_at – Calculate byte offsets
  3. 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.

A file is divided into segments such that each segment is associated with one process.
File pointers map each process's memory to a dedicated location in the distributed file.

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_File_open mode parameters.
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
 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement