# MPI file views: where offset 2 lands

A view-relative offset is not an absolute byte address. The following constructed
layout makes the difference visible without assuming a disk, filesystem or MPI runtime.

## Exact example

A file has a 128-byte header. An etype is four contiguous bytes, with size and
extent both four bytes. One filetype selects etypes at relative bytes 0 and 8.
Its lower bound is zero. Compare a 16-byte extent with a 12-byte extent.

| View offset (etypes) | Absolute byte, extent 16 | Absolute byte, extent 12 |
| --- | --- | --- |
| 0 | 128 | 128 |
| 1 | 136 | 136 |
| 2 | 144 | 140 |
| 3 | 152 | 148 |
| 4 | 160 | 152 |
| 5 | 168 | 160 |

Both filetypes contain eight payload bytes. Their repetition steps differ.
For the 16-byte layout, reading four etypes beginning at offset 1 selects
[136,140), [144,148), [152,156), [160,164): 16 useful bytes in a 28-byte span.
A contiguous memory destination needs those 16 bytes, not the intervening file
holes. This span is not a claim that the storage device reads 28 bytes.

For m visible etypes per repetition, ordered byte starts s, displacement d
and repetition extent E, the restricted model uses:

    byte(k) = d + floor(k / m) * E + s[k mod m]

For offset 2 in the first layout, this is 128 + 1 * 16 + 0 = 144,
not 128 + 2 * 4 = 136. An initial hole would also move offset zero.

## Why the distinction matters

MPI repeats a filetype and counts offsets over visible etypes.
[MPI I/O definitions](https://www.mpi-forum.org/docs/mpi-4.1/mpi41-report/node350.htm)
describe that contract.
[Resizing a datatype](https://www.mpi-forum.org/docs/mpi-4.1/mpi41-report/node103.htm)
changes its bounds and repetition stride without adding payload.
For an actual file handle,
[MPI_File_get_byte_offset](https://www.mpi-forum.org/docs/mpi-4.1/mpi41-report/node369.htm)
performs the view-relative-to-byte conversion.

The ROMIO paper shows why supplying a complete access pattern gives an
implementation more optimization opportunities. It does not establish a universal
speedup from a view. See [Thakur, Gropp and Lusk, Frontiers 1999](https://web.cels.anl.gov/~thakur/papers/romio-coll.pdf)
and the connected [collective I/O](https://hesela.dev/terms/collective-io/)
and [two-phase I/O](https://hesela.dev/terms/two-phase-io/) definitions.

## Run and scope

Use Node.js with built-in test support. No packages or network access are needed:

    node --test model.test.mjs
    node --input-type=module -e 'import {example} from "./model.mjs"; console.table(example())'

[Model](./model.mjs) | [Tests](./model.test.mjs) | [Definition](https://hesela.dev/terms/mpi-file-view/)

The model accepts BigInt coordinates, a nonempty ordered list of nonoverlapping
contiguous etypes, and an extent containing the whole pattern. It rejects unsafe
Number coercions, invalid units and unsupported layouts. It does not support
holes inside an etype, overlapping repetitions, heterogeneous data conversion,
EOF, pointer state, MPI errors, or concurrent operations. It is not an MPI
conformance test, an implementation of MPI, or a reproduction of ROMIO performance.

Tests independently enumerate 502 small layouts through five repetitions,
exercise initial holes and very large offsets, and check invalid inputs.
There is no sampled population or statistical uncertainty: these are deterministic
layout examples, not measured performance. No third-party data or figures are copied.
