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>
impl<'a> DynBufferMut<'a>
Sourcepub fn new<T: Equivalence>(buf: &'a mut [T]) -> Self
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.
Sourcepub fn is<T: Equivalence>(&self) -> bool
pub fn is<T: Equivalence>(&self) -> bool
Tests whether the buffer type matches T
.
Sourcepub fn downcast<T: Equivalence>(self) -> Option<&'a mut [T]>
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)
15fn test_user_operations<C: Communicator>(comm: C) {
16 let rank = comm.rank();
17 let size = comm.size();
18 let mut h = 0;
19 comm.all_reduce_into(
20 &(rank + 1),
21 &mut h,
22 &UserOperation::commutative(|x, y| {
23 let x: &[Rank] = x.downcast().unwrap();
24 let y: &mut [Rank] = y.downcast().unwrap();
25 for (&x_i, y_i) in x.iter().zip(y) {
26 *y_i += x_i;
27 }
28 }),
29 );
30 assert_eq!(h, size * (size + 1) / 2);
31}
More examples
examples/immediate_reduce.rs (line 17)
14fn test_user_operations<C: Communicator>(comm: C) {
15 let op = UserOperation::commutative(|x, y| {
16 let x: &[Rank] = x.downcast().unwrap();
17 let y: &mut [Rank] = y.downcast().unwrap();
18 for (&x_i, y_i) in x.iter().zip(y) {
19 *y_i += x_i;
20 }
21 });
22 let rank = comm.rank();
23 let size = comm.size();
24 let mut c = 0;
25 mpi::request::scope(|scope| {
26 comm.immediate_all_reduce_into(scope, &rank, &mut c, &op)
27 .wait();
28 });
29 assert_eq!(c, size * (size - 1) / 2);
30}
Sourcepub unsafe fn from_raw<T>(
ptr: *mut T,
len: Count,
datatype: DatatypeRef<'a>,
) -> Self
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 holdslen
elements of the type described bydatatype
.
Examples found in repository?
examples/datatype_dup.rs (line 21)
6fn main() {
7 let universe = mpi::initialize().unwrap();
8 let world = universe.world();
9
10 let root_process = world.process_at_rank(0);
11
12 let int_type = i32::equivalent_datatype().dup();
13
14 let mut ints = if world.rank() == 0 {
15 [1i32, 2, 3, 4]
16 } else {
17 [0, 0, 0, 0]
18 };
19
20 let mut buffer =
21 unsafe { DynBufferMut::from_raw(ints.as_mut_ptr(), ints.count(), int_type.as_ref()) };
22
23 root_process.broadcast_into(&mut buffer);
24
25 assert_eq!([1, 2, 3, 4], ints);
26}
Sourcepub fn as_mut_ptr(&mut self) -> *mut c_void
pub fn as_mut_ptr(&mut self) -> *mut c_void
Returns the underlying raw pointer.
Sourcepub fn reborrow_mut(&mut self) -> DynBufferMut<'_>
pub fn reborrow_mut(&mut self) -> DynBufferMut<'_>
Reborrows the buffer mutably with a shorter lifetime.
Trait Implementations§
Source§impl<'a> AsDatatype for DynBufferMut<'a>
impl<'a> AsDatatype for DynBufferMut<'a>
Source§type Out = DatatypeRef<'a>
type Out = DatatypeRef<'a>
The type of the associated MPI datatype (e.g.
SystemDatatype
or UserDatatype
)Source§fn as_datatype(&self) -> Self::Out
fn as_datatype(&self) -> Self::Out
The associated MPI datatype
Source§impl<'a> Collection for DynBufferMut<'a>
impl<'a> Collection for DynBufferMut<'a>
Source§impl<'a> Debug for DynBufferMut<'a>
impl<'a> Debug for DynBufferMut<'a>
Source§impl<'a> Pointer for DynBufferMut<'a>
impl<'a> Pointer for DynBufferMut<'a>
Source§impl<'a> PointerMut for DynBufferMut<'a>
impl<'a> PointerMut for DynBufferMut<'a>
Source§fn pointer_mut(&mut self) -> *mut c_void
fn pointer_mut(&mut self) -> *mut c_void
A mutable pointer to the starting address in memory
impl<'a> Buffer for DynBufferMut<'a>
impl<'a> BufferMut for DynBufferMut<'a>
impl<'a> Send for DynBufferMut<'a>
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<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
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 Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
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>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
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>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Approximate the subject to a given type with a specific scheme.