Skip to content

tensor4all/rsmpi-rt

 
 

Repository files navigation

rsmpi-rt

GitHub Actions Documentation License: Apache License 2.0 or MIT

Rust MPI bindings with runtime library loading. Fork of rsmpi v0.8.1.

Status: Experimental / Proof of Concept. This project aims to eventually merge its runtime-loading backend upstream into rsmpi.

The key addition over upstream rsmpi is the mpi-rt-sys-backend: a backend based on MPItrampoline's MPIABI that loads MPI at runtime via dlopen, requiring no C compiler, system MPI headers, or libclang at build time.

Motivation

The primary goal is to enable calling Rust MPI code from Julia and Python without build-time MPI dependencies. By loading MPI at runtime, Rust libraries can share the same MPI communicator with MPI.jl and mpi4py, enabling seamless multi-language HPC workflows.

Quick Start

[dependencies]
mpi = { git = "https://github.com/tensor4all/rsmpi-rt", default-features = false, features = ["mpi-rt-sys-backend"] }
use mpi::traits::*;

fn main() {
    let universe = mpi::initialize().unwrap();
    let world = universe.world();
    println!("Hello from rank {} of {}", world.rank(), world.size());
}
export MPI_RT_LIB=/path/to/libmpiwrapper.so
mpiexec -n 4 cargo run

Backend Selection

Feature Description Default
mpi-sys-backend Bindgen-based (requires C compiler, system MPI, libclang) Yes
mpi-rt-sys-backend MPItrampoline/MPIABI-based runtime loading (no build-time MPI deps) No

The two backends are mutually exclusive.

mpi-rt-sys-backend (recommended for this fork)

No build-time MPI dependencies. The MPI library is loaded at runtime via MPIwrapper.

[dependencies]
mpi = { git = "https://github.com/tensor4all/rsmpi-rt", default-features = false, features = ["mpi-rt-sys-backend"] }

With optional features:

[dependencies]
mpi = { git = "https://github.com/tensor4all/rsmpi-rt", default-features = false, features = ["mpi-rt-sys-backend", "user-operations", "derive"] }

Runtime setup: Set MPI_RT_LIB to the path of an MPIwrapper library:

export MPI_RT_LIB=/path/to/libmpiwrapper.so
mpiexec -n 4 ./my_program

To build MPIwrapper (requires a system MPI):

git clone https://github.com/eschnett/MPIwrapper
cd MPIwrapper
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$HOME/.local
cmake --build build
cmake --install build
export MPI_RT_LIB=$HOME/.local/lib/libmpiwrapper.so

mpi-sys-backend

Traditional compile-time binding via rust-bindgen. Same as upstream rsmpi. Requires a C compiler, system MPI installation, and libclang.

[dependencies]
mpi = { git = "https://github.com/tensor4all/rsmpi-rt" }

See the upstream rsmpi README for detailed build requirements.

Optional Features

Feature Description
user-operations User-defined reduction operations via libffi
derive #[derive(Equivalence)] for sending structs over MPI
complex Support for num-complex types

Interoperability Tests

Integration tests verify that Rust MPI code can run alongside mpi4py and MPI.jl under the same mpiexec, sharing MPI_COMM_WORLD via MPMD launch:

# Run the cross-language interop test (requires Python/mpi4py and Julia/MPI.jl)
bash tests/interop/run_interop.sh

See tests/interop/ for details.

Documentation

Generate docs locally:

cargo doc --workspace --no-deps --features mpi-sys-backend,user-operations,derive,complex

Examples

See examples/.

License

Licensed under either of

at your option.

About

MPI bindings for Rust

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Rust 82.4%
  • Python 15.5%
  • Shell 1.1%
  • Other 1.0%