Docs · I/O adapters
Intercept MPI-IO.
The MPI-IO interceptor takes over MPI_File_* calls on clio:: files and stores the data in the CLIO filesystem module. It is a drop-in for MPI codes that do independent or explicit-offset I/O. It is not a parallel I/O library: collective calls run as independent I/O on each rank.
- Library
- libclio_cte_mpiio.so
- Build
- CLIO_CTE_ENABLE_MPIIO_ADAPTER=ON CLIO_CORE_ENABLE_ELF=ON
- MPI
- OpenMPI or MPICH
- Load
- LD_PRELOAD, before libmpi
- Install
- Source builds: Spack (+mpiio) or CMake
How it works
MPI_File_open on a filename with a clio:: component opens the file in the clio_cte_filesystem module and returns an MPI_File that is an opaque token for that descriptor. Every later call on that handle is served by the interceptor and never reaches the MPI library. Other filenames go to the real MPI-IO. Each rank opens the file through its own descriptor; the communicator passed to MPI_File_open does not coordinate anything.
1. Build it
$ cmake -S . -B build -DCLIO_CORE_ENABLE_ELF=ON \
-DCLIO_CTE_ENABLE_MPIIO_ADAPTER=ON -DCLIO_CORE_ENABLE_MPI=ON
$ cmake --build build -j"$(nproc)"
$ ls build/bin/libclio_cte_mpiio.soConfigure finds MPI with find_package(MPI) and asks mpicc whether it is OpenMPI or MPICH, because the interceptor fills implementation-specific MPI_Status fields. If it cannot tell, configure stops; pass -DCLIO_CTE_OPENMPI=ON or -DCLIO_CTE_MPICH=ON. Build with the same MPI your application uses. Source builds only; see Install.
2. Start a runtime on every node
$ build/bin/clio-run start &Ranks attach to the runtime on their own node. Its configuration must compose a clio_cte_filesystem pool, as the default configuration does. For several nodes, start the runtime on each with a shared hostfile; see the Context Runtime docs.
3. Run an MPI program under the interceptor
Each rank writes its own block at an explicit offset, syncs, and reads it back.
#include <mpi.h>
#include <stdio.h>
#define N 1024
int main(int argc, char **argv) {
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
const char *path = argc > 1 ? argv[1] : "clio::/demo/mpi.bin";
int out[N], in[N];
for (int i = 0; i < N; ++i) out[i] = rank * N + i;
MPI_Offset off = (MPI_Offset)rank * N * sizeof(int);
MPI_File fh;
MPI_File_open(MPI_COMM_WORLD, path, MPI_MODE_CREATE | MPI_MODE_RDWR,
MPI_INFO_NULL, &fh);
MPI_File_write_at(fh, off, out, N, MPI_INT, MPI_STATUS_IGNORE);
MPI_File_sync(fh);
MPI_File_read_at(fh, off, in, N, MPI_INT, MPI_STATUS_IGNORE);
MPI_File_close(&fh);
int ok = 1;
for (int i = 0; i < N; ++i) ok &= (in[i] == out[i]);
printf("rank %d: %s\n", rank, ok ? "ok" : "MISMATCH");
MPI_Finalize();
return ok ? 0 : 1;
}$ mpicc -o hello_mpiio hello_mpiio.c
$ mpirun -np 2 env LD_PRELOAD=$PWD/build/bin/libclio_cte_mpiio.so \
./hello_mpiio clio::/demo/mpi.bin
rank 0: ok
rank 1: okWrapping the program in env sets LD_PRELOAD in every rank, whatever launcher you use. The interceptor must be loaded before libmpi, or libmpi's own MPI_File_* symbols win; LD_PRELOAD guarantees that.
What is intercepted
- Open and close
MPI_File_open,MPI_File_close,MPI_File_delete.MPI_MODE_CREATE,MPI_MODE_APPEND,MPI_MODE_EXCLand the access modes map toopenflags.- Read and write
- Independent (
MPI_File_read,_write), collective (_all), explicit-offset (_at,_at_all), shared-pointer (_shared) and ordered (_ordered) variants, and the nonblockingMPI_File_iread,_iwrite,_iread_at,_iwrite_at,_iread_shared,_iwrite_shared. - Position
MPI_File_seek,MPI_File_seek_shared,MPI_File_get_position.- Metadata
MPI_File_sync,MPI_File_get_size,MPI_File_set_size,MPI_File_get_info,MPI_File_set_info,MPI_File_get_amode,MPI_File_set_atomicity,MPI_File_get_atomicity,MPI_File_set_view.
MPI_Init, MPI_Finalize, MPI_Wait and MPI_Waitall are also defined by the library and pass straight through to MPI.
Semantics
- Collectives are independent.
_all,_sharedand_orderedcalls behave like their independent counterparts on each rank. There is no collective buffering or aggregation at this layer; the filesystem module decides placement. - Shared and ordered file pointers are per process, not shared between ranks. Use explicit offsets when ranks write to one file.
- Nonblocking calls complete immediately. The
ivariants do the transfer before returning and hand backMPI_REQUEST_NULL. - File views.
MPI_File_set_viewflattens the filetype into byte blocks, and the explicit-offset calls (_at,_at_all,i..._at) map data through it; derived memory datatypes are gathered and scattered the same way. This covers the non-contiguous views that parallel HDF5 sets for collective I/O. The file-pointer calls (no_at) need the default view and a contiguous memory datatype. - Refused, not guessed. A datatype built with a constructor the interceptor does not decode (such as subarray or darray), a data representation other than
native, or a file-pointer call under a non-default view returnsMPI_ERR_UNSUPPORTED_OPERATIONand logs the reason, instead of transferring the bytes as if they were contiguous. - Errors are MPI error classes. Failures of the filesystem module are mapped from
errnoto an MPI error class and returned by the call.MPI_File_syncmakes the file durable on a persistent device, likefsyncin the POSIX interceptor, and reports any failure; so does a failingMPI_File_close.
Limits
- The project's own unit test (
clio_cte_mpiio_unit_tests) runs as a single-rank program. Validate multi-rank access patterns on your system before relying on them. - Linux only, dynamically linked programs only, and only
clio::filenames are redirected. - Data lives only in the CTE. Its durability is decided by the tiers the runtime composes.
Where to go next
- HDF5 VOL connector, if your MPI code does its I/O through HDF5.
- Configuration reference.