Skip to content

Provide a derive macro for the trait `mpi::datatype::Equivalence` from https://github.com/bsteinb/rsmpi

Notifications You must be signed in to change notification settings

Davier/rsmpi_derive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Derive macro for rsmpi trait Equivalence

The trait mpi::datatype::Equivalence describes a rust struct as a MPI_Datatype in order to synchronize it automatically.

This crate provides a derive macro to automatically implement it for plain structures composed recursively of:

  • types that implement the Equivalence trait
  • arrays of those types
  • tuples of those types

Example

The following example shows how to broadcast a struct.

use mpi::traits::*;
use mpi_derive::Equivalence;

#[derive(Equivalence, Default)]
struct ComplexDatatype {
    b: bool,
    ints: [i32; 4],
    tuple: ([f32; 2], u8),
}

fn main() {
    let universe = mpi::initialize().unwrap();
    let world = universe.world();

    let root_process = world.process_at_rank(0);

    let mut data = if world.rank() == 0 {
        ComplexDatatype {
            b: true,
            ints: [1, -2, 3, -4],
            tuple: ([-0.1, 0.1], 7),
        }
    } else {
        ComplexDatatype::default()
    };

    root_process.broadcast_into(&mut data);

    assert_eq!(true, data.b);
    assert_eq!([1, -2, 3, -4], data.ints);
    assert_eq!([-0.1, 0.1], data.tuple.0);
    assert_eq!(7, data.tuple.1);
}

Limitations

  • Type aliases cannot be supported
  • enums are not implemented yet

About

Provide a derive macro for the trait `mpi::datatype::Equivalence` from https://github.com/bsteinb/rsmpi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages