{"id":13648655,"url":"https://github.com/rsmpi/rsmpi","last_synced_at":"2025-12-12T12:47:15.918Z","repository":{"id":35210309,"uuid":"39469270","full_name":"rsmpi/rsmpi","owner":"rsmpi","description":"MPI bindings for Rust","archived":false,"fork":false,"pushed_at":"2024-10-18T15:14:17.000Z","size":4204,"stargazers_count":485,"open_issues_count":23,"forks_count":52,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-10-20T09:13:32.169Z","etag":null,"topics":["mpi","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/mpi","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rsmpi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-21T20:51:28.000Z","updated_at":"2024-10-20T08:12:29.000Z","dependencies_parsed_at":"2023-09-29T00:09:30.171Z","dependency_job_id":"37734485-9a10-4327-be5c-e3ff00f7d1c8","html_url":"https://github.com/rsmpi/rsmpi","commit_stats":{"total_commits":532,"total_committers":24,"mean_commits":"22.166666666666668","dds":0.424812030075188,"last_synced_commit":"98d3a8bb65f4ad985ea7f2ee7b5f4df2ea66cfcd"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsmpi%2Frsmpi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsmpi%2Frsmpi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsmpi%2Frsmpi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsmpi%2Frsmpi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsmpi","download_url":"https://codeload.github.com/rsmpi/rsmpi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223896472,"owners_count":17221441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mpi","rust"],"created_at":"2024-08-02T01:04:25.902Z","updated_at":"2025-12-12T12:47:15.911Z","avatar_url":"https://github.com/rsmpi.png","language":"Rust","funding_links":[],"categories":["Rust","Parallel and Async Library"],"sub_categories":[],"readme":"# MPI bindings for Rust\n\n[![GitHub Actions][actions-shield]][actions]\n[![Documentation][doc-shield]][doc]\n[![Crates.io][crate-shield]][crate]\n[![License: Apache License 2.0 or MIT][license-shield]][license]\n\nThe [Message Passing Interface][MPI] (MPI) is a specification for a\nmessage-passing style concurrency library. Implementations of MPI are often used to structure\nparallel computation on High Performance Computing systems. The MPI specification describes\nbindings for the C programming language (and through it C++) as well as for the Fortran\nprogramming language. This library tries to bridge the gap into a more rustic world.\n\n[actions-shield]: https://github.com/rsmpi/rsmpi/workflows/Test/badge.svg\n[actions]: https://github.com/rsmpi/rsmpi/actions\n[doc-shield]: https://docs.rs/mpi/badge.svg\n[doc]: https://docs.rs/mpi\n[crate-shield]: https://img.shields.io/crates/v/mpi.svg?style=flat-square\n[crate]: https://crates.io/crates/mpi\n[license-shield]: https://img.shields.io/badge/license-Apache_License_2.0_or_MIT-blue.svg?style=flat-square\n[license]: https://github.com/rsmpi/rsmpi#license\n[MPI]: http://www.mpi-forum.org\n\n## Requirements\n\nAn implementation of the C language interface that conforms to MPI-3.1. `rsmpi` is currently tested with these implementations:\n- [OpenMPI][OpenMPI] 4.0.3 on Ubuntu-20.04, 4.1.2 on macOS\n- [MPICH][MPICH] 3.3.2 on Ubuntu 20.04\n- [MS-MPI (Windows)][MS-MPI] 10.1.2 on Windows 2022\n\nUsers have also had success with these MPI implementations, but they are not tested in CI:\n- [Spectrum MPI][Spectrum-MPI] 10.3.0.1\n- [Cray MPI][Cray-MPI] 8.1.16 with `PrgEnv-amd/8.3.3`\n\nFor a reasonable chance of success with `rsmpi` with any MPI implementation, you must have one of:\n\n- export `MPI_PKG_CONFIG` to be the name or path for pkg-config for your implementation\n  - `rsmpi` automatically uses `CRAY_MPICH_DIR` on Cray environments so the above need not be set\n  - `mpich` and `ompi` are tried by default as a last resort\n  - Tip: test with a command like `pkg-config --cflags --libs mpich`\n- The implementation provides a C compiler wrapper `mpicc`\n  - export `MPICC=/path/to/mpicc` to specify fully\n  - otherwise tries `mpicc` in `$PATH`\n  - `mpicc -show` should print the full command line that is used to invoke the wrapped C compiler in gcc-compatible syntax (e.g., `-lmpi`, `-I/usr/local/include`, ...)\n- On Windows,\n  - for MS-MPI the variables `MSMPI_INC` and either `MSMPI_LIB32` or `MSMPI_LIB64` should be set\n  - for Intel MPI the variable `I_MPI_ROOT` should be set\n\nSince the MPI standard leaves some details of the C API unspecified (whether to implement certain constants and even functions using preprocessor macros or native C constructs, the details of most types, etc.) `rsmpi` takes a two step approach to generating functional low-level bindings.\n\nFirst, it uses a thin static library written in C (see [rsmpi.h][rsmpih] and [rsmpi.c][rsmpic]) that tries to capture the underspecified identifiers and re-exports them with a fixed C API. This library is built from [build.rs][buildrs] using the `gcc` crate.\n\nSecond, to generate FFI definitions tailored to each MPI implementation, `rsmpi` uses `rust-bindgen` which needs `libclang`. See the [bindgen project page][bindgen] for more information.\n\nFurthermore, `rsmpi` uses the `libffi` crate which installs the native `libffi` which depends on certain build tools. See the [libffi project page][libffi] for more information.\n\n[OpenMPI]: https://www.open-mpi.org\n[MPICH]: https://www.mpich.org\n[MS-MPI]: https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi\n[Spectrum-MPI]: https://www.ibm.com/products/spectrum-mpi\n[Cray-MPI]: https://docs.nersc.gov/development/programming-models/mpi/cray-mpich/\n[rsmpih]: https://github.com/rsmpi/rsmpi/blob/main/mpi-sys/src/rsmpi.h\n[rsmpic]: https://github.com/rsmpi/rsmpi/blob/main/mpi-sys/src/rsmpi.c\n[buildrs]: https://github.com/rsmpi/rsmpi/blob/main/mpi-sys/build.rs\n[bindgen]: https://github.com/servo/rust-bindgen\n[libffi]: https://github.com/tov/libffi-rs\n\n## Usage\n\nAdd the `mpi` crate as a dependency in your `Cargo.toml`:\n\n```toml\n# \"features\" is optional\n[dependencies]\nmpi = { version = \"0.8.1\", features = [\"user-operations\", \"derive\"] }\n```\n\nThen use it in your program like this:\n\n```rust\n\nuse mpi::request::WaitGuard;\nuse mpi::traits::*;\n\nfn main() {\n    let universe = mpi::initialize().unwrap();\n    let world = universe.world();\n    let size = world.size();\n    let rank = world.rank();\n\n    let next_rank = (rank + 1) % size;\n    let previous_rank = (rank - 1 + size) % size;\n\n    let msg = vec![rank, 2 * rank, 4 * rank];\n    mpi::request::scope(|scope| {\n        let _sreq = WaitGuard::from(\n            world\n                .process_at_rank(next_rank)\n                .immediate_send(scope, \u0026msg[..]),\n        );\n\n        let (msg, status) = world.any_process().receive_vec();\n\n        println!(\n            \"Process {} got message {:?}.\\nStatus is: {:?}\",\n            rank, msg, status\n        );\n        let x = status.source_rank();\n        assert_eq!(x, previous_rank);\n        assert_eq!(vec![x, 2 * x, 4 * x], msg);\n\n        let root_rank = 0;\n        let root_process = world.process_at_rank(root_rank);\n\n        let mut a;\n        if world.rank() == root_rank {\n            a = vec![2, 4, 8, 16];\n            println!(\"Root broadcasting value: {:?}.\", \u0026a[..]);\n        } else {\n            a = vec![0; 4];\n        }\n        root_process.broadcast_into(\u0026mut a[..]);\n        println!(\"Rank {} received value: {:?}.\", world.rank(), \u0026a[..]);\n        assert_eq!(\u0026a[..], \u0026[2, 4, 8, 16]);\n    });\n}\n```\n\n## Features\n\nThe bindings follow the MPI 3.1 specification.\n\nCurrently supported:\n\n- **Groups, Contexts, Communicators**:\n  - Group and (Intra-)Communicator management from section 6 is mostly complete.\n  - no Inter-Communicators\n  - no process topologies\n- **Point to point communication**:\n  - standard, buffered, synchronous and ready mode send in blocking and non-blocking variants\n  - receive in blocking and non-blocking variants\n  - send-receive\n  - probe\n  - matched probe/receive\n- **Collective communication**:\n  - barrier\n  - broadcast\n  - (all) gather\n  - scatter\n  - all to all\n  - varying counts operations\n  - reductions/scans\n  - blocking and non-blocking variants\n- **Datatypes**: Bridging between Rust types and MPI basic types as well as custom MPI datatypes which can act as views into buffers.\n\nNot supported (yet):\n\n- One-sided communication (RMA)\n- MPI parallel I/O\n- A million small things\n\n\n### Optional Cargo Features\n\nThese optional features can be enabled in your cargo manifest. See the [Usage](#usage) section\nabove.\n\n`user-operations` enables capturing lambdas and safe creation in `UserOperation`. This feature\nrequires the `libffi` system library, which is not available on all systems out-of-the-box.\n\n```rust\nlet mut h = 0;\ncomm.all_reduce_into(\n    \u0026(rank + 1),\n    \u0026mut h,\n    \u0026UserOperation::commutative(|x, y| {\n        let x: \u0026[Rank] = x.downcast().unwrap();\n        let y: \u0026mut [Rank] = y.downcast().unwrap();\n        for (\u0026x_i, y_i) in x.iter().zip(y) {\n            *y_i += x_i;\n        }\n    }),\n);\n```\n\n`derive` enables the `Equivalence` derive macro, which makes it easy to send structs\nover-the-wire without worrying about safety around padding, and allowing arbitrary datatype\nmatching between structs with the same field order but different layout.\n\n```rust\n#[derive(Equivalence)]\nstruct MyProgramOpts {\n    name: [u8; 100],\n    num_cycles: u32,\n    material_properties: [f64; 20],\n}\n```\n\n### On disabling the `mpi-sys/runtime` feature\n\nFor a standard install of LLVM on Linux, the `runtime` feature can be disabled (e.g., via `--no-default-features`) with no consequences because `libclang.so` will be found in a default path. (To use a non-default path, `LD_LIBRARY_PATH` would have to be set.) On MacOS, standard installs (like Homebrew) do not put `libclang.dylib` in a default path. See [the CI configuration](.github/workflows/test.yaml) for examples of correctly setting `DYLD_LIBRARY_PATH` for MacOS. See [`clang-sys` documentation on linking](https://github.com/KyleMayes/clang-sys?tab=readme-ov-file#linking) for more details.\n\n## Documentation\n\nEvery public item of `rsmpi` should at least have a short piece of documentation associated with it. Documentation can be generated via:\n\n```\ncargo doc\n```\n\nDocumentation for the latest version of the crate released to crates.io is [hosted on Github pages][doc].\n\n## Examples\n\nSee files in [examples/][examples]. These examples also act as [integration tests][actions].\n\n[examples]: https://github.com/rsmpi/rsmpi/tree/master/examples\n\n## Python integration\n\nIt is possible to use `rsmpi` with a communicator provided by [mpi4py](https://mpi4py.readthedocs.io/en/stable/). An example project demonstrating this is [mpi4py_with_rsmpi](https://github.com/betckegroup/mpi4py_with_rsmpi).\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally\nsubmitted for inclusion in the work by you, as defined in the Apache-2.0\nlicense, shall be dual licensed as above, without any additional terms or\nconditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsmpi%2Frsmpi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsmpi%2Frsmpi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsmpi%2Frsmpi/lists"}