Struct mpi::datatype::DynBufferMut

source ·
pub struct DynBufferMut<'a> { /* private fields */ }
Expand description

A mutable dynamically-typed buffer.

The buffer has a definite length and MPI datatype, but it is not yet known which Rust type it corresponds to. This is the MPI analogue of &mut Any. It is semantically equivalent to the mutable trait object reference &mut BufferMut.

Implementations§

source§

impl<'a> DynBufferMut<'a>

source

pub fn new<T: Equivalence>(buf: &'a mut [T]) -> Self

Creates a mutable buffer from a mutable slice with whose type has an MPI equivalent.

source

pub fn is<T: Equivalence>(&self) -> bool

Tests whether the buffer type matches T.

source

pub fn downcast<T: Equivalence>(self) -> Option<&'a mut [T]>

Returns some mutable slice if the type matches T, or None if it doesn’t.

Examples found in repository?
examples/reduce.rs (line 24)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn test_user_operations<C: Communicator>(comm: C) {
    let rank = comm.rank();
    let size = comm.size();
    let mut h = 0;
    comm.all_reduce_into(
        &(rank + 1),
        &mut h,
        &UserOperation::commutative(|x, y| {
            let x: &[Rank] = x.downcast().unwrap();
            let y: &mut [Rank] = y.downcast().unwrap();
            for (&x_i, y_i) in x.iter().zip(y) {
                *y_i += x_i;
            }
        }),
    );
    assert_eq!(h, size * (size + 1) / 2);
}
More examples
Hide additional examples
examples/immediate_reduce.rs (line 17)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn test_user_operations<C: Communicator>(comm: C) {
    let op = UserOperation::commutative(|x, y| {
        let x: &[Rank] = x.downcast().unwrap();
        let y: &mut [Rank] = y.downcast().unwrap();
        for (&x_i, y_i) in x.iter().zip(y) {
            *y_i += x_i;
        }
    });
    let rank = comm.rank();
    let size = comm.size();
    let mut c = 0;
    mpi::request::scope(|scope| {
        comm.immediate_all_reduce_into(scope, &rank, &mut c, &op)
            .wait();
    });
    assert_eq!(c, size * (size - 1) / 2);
}
source

pub unsafe fn from_raw<T>( ptr: *mut T, len: Count, datatype: DatatypeRef<'a> ) -> Self

Creates a buffer from its raw components. The buffer must remain valid for 'a and the pointer must not be null.

§Safety
  • Buffer pointed to by ptr must live as long as 'a. There must be no other live reference to the buffer in Rust.
  • ptr must point to an object that holds len elements of the type described by datatype.
Examples found in repository?
examples/datatype_dup.rs (line 21)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn main() {
    let universe = mpi::initialize().unwrap();
    let world = universe.world();

    let root_process = world.process_at_rank(0);

    let int_type = i32::equivalent_datatype().dup();

    let mut ints = if world.rank() == 0 {
        [1i32, 2, 3, 4]
    } else {
        [0, 0, 0, 0]
    };

    let mut buffer =
        unsafe { DynBufferMut::from_raw(ints.as_mut_ptr(), ints.count(), int_type.as_ref()) };

    root_process.broadcast_into(&mut buffer);

    assert_eq!([1, 2, 3, 4], ints);
}
source

pub fn len(&self) -> usize

Returns the number of elements in the buffer.

source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty

source

pub fn as_ptr(&self) -> *const c_void

Returns the underlying raw pointer.

source

pub fn as_mut_ptr(&mut self) -> *mut c_void

Returns the underlying raw pointer.

source

pub fn reborrow(&self) -> DynBuffer<'_>

Reborrows the buffer with a shorter lifetime.

source

pub fn reborrow_mut(&mut self) -> DynBufferMut<'_>

Reborrows the buffer mutably with a shorter lifetime.

source

pub fn downgrade(self) -> DynBuffer<'a>

Makes the buffer immutable.

Trait Implementations§

source§

impl<'a> AsDatatype for DynBufferMut<'a>

§

type Out = DatatypeRef<'a>

The type of the associated MPI datatype (e.g. SystemDatatype or UserDatatype)
source§

fn as_datatype(&self) -> Self::Out

The associated MPI datatype
source§

impl<'a> Collection for DynBufferMut<'a>

source§

fn count(&self) -> Count

How many things are in this collection.
source§

impl<'a> Debug for DynBufferMut<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Pointer for DynBufferMut<'a>

source§

fn pointer(&self) -> *const c_void

A pointer to the starting address in memory
source§

impl<'a> PointerMut for DynBufferMut<'a>

source§

fn pointer_mut(&mut self) -> *mut c_void

A mutable pointer to the starting address in memory
source§

impl<'a> Buffer for DynBufferMut<'a>

source§

impl<'a> BufferMut for DynBufferMut<'a>

source§

impl<'a> Send for DynBufferMut<'a>

source§

impl<'a> Sync for DynBufferMut<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for DynBufferMut<'a>

§

impl<'a> RefUnwindSafe for DynBufferMut<'a>

§

impl<'a> Unpin for DynBufferMut<'a>

§

impl<'a> UnwindSafe for DynBufferMut<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

§

type Err = NoError

The error type produced by a failed conversion.
source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, Dst> ConvAsUtil<Dst> for T

source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
source§

impl<T> ConvUtil for T

source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Src> TryFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<Src> ValueFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.