rsmpi-rt provides Rust bindings to MPI with two interchangeable backends selected via Cargo feature flags.
rsmpi-rt/
mpi (root crate) -- High-level Rust MPI API
mpi-sys/ -- Bindgen-based FFI (compile-time linking)
mpi-rt-sys/ -- MPIABI-based FFI (runtime loading)
mpi-derive/ -- Proc-macro for #[derive(Equivalence)]
build-probe-mpi/ -- Build-time MPI detection
mpi (src/lib.rs)
/ \
[mpi-sys-backend] [mpi-rt-sys-backend]
| |
mpi-sys mpi-rt-sys
| |
bindgen + cc libloading
| |
system MPI libs MPIwrapper (runtime)
The two backends are mutually exclusive, enforced by compile-time checks in src/lib.rs:
#[cfg(all(feature = "mpi-sys-backend", feature = "mpi-rt-sys-backend"))]
compile_error!("...");| Feature | Backend Crate | Default |
|---|---|---|
mpi-sys-backend |
mpi-sys |
Yes |
mpi-rt-sys-backend |
mpi-rt-sys |
No |
Both backends export the same public API surface. The mpi crate's ffi module re-exports from whichever backend is active:
pub mod ffi {
#[cfg(feature = "mpi-sys-backend")]
pub use mpi_sys::*;
#[cfg(feature = "mpi-rt-sys-backend")]
pub use mpi_rt_sys::*;
}This means all higher-level code in the mpi crate uses ffi::MPI_* types and functions without knowing which backend is active.
Both backends provide:
- MPI types:
MPI_Comm,MPI_Datatype, etc. - MPI functions:
MPI_Init,MPI_Send, etc. - Constant accessors:
RSMPI_COMM_WORLD_fn(),RSMPI_DATATYPE_NULL_fn(), etc.
The RSMPI_*_fn() accessor pattern is used because:
mpi-sys: MPI constants areexternglobals that cannot be used as Rust constants directly. The_fn()wrappers inmpi-sys/src/constant_accessors.rsprovide a uniform function-call interface.mpi-rt-sys: Constants are loaded from the shared library at runtime, so they are naturally functions.
Uses rust-bindgen to generate FFI bindings at build time from the system MPI headers. Requires:
- A C compiler
- System MPI installation (OpenMPI, MPICH, MS-MPI, etc.)
libclang(for bindgen)
See mpi-sys/build.rs and build-probe-mpi/ for the build-time detection logic.
Uses the MPIABI standard to load MPI symbols at runtime via libloading. Requires:
- No C compiler at build time
- An MPIABI-compatible wrapper library at runtime (e.g., MPIwrapper)
See mpiabi-dynamic-loading.md for details on the runtime loading mechanism.