Struct UserOperation

Source
pub struct UserOperation<'a> { /* private fields */ }
Expand description

A user-defined operation.

The lifetime 'a of the operation is limited by the lifetime of the underlying closure.

For safety reasons, UserOperation is in of itself not considered an Operation, but a reference of it is. This limitation may be lifted in the future when Request objects can store finalizers.

Note: When a UserOperation is passed to a non-blocking API call, it must outlive the completion of the request. This is normally enforced by the safe API, so this is only a concern if you use the unsafe API. Do not rely on MPI’s internal reference-counting here, because once UserOperation is destroyed, the closure object will be deallocated even if the MPI_Op handle is still alive due to outstanding references.

§Examples

See examples/reduce.rs and examples/immediate_reduce.rs

Implementations§

Source§

impl<'a> UserOperation<'a>

Source

pub fn associative<F>(function: F) -> Self
where F: Fn(DynBuffer<'_>, DynBufferMut<'_>) + Sync + 'a,

Define an operation using a closure. The operation must be associative.

This is a more readable shorthand for the new method. Refer to new for more information.

Source

pub fn commutative<F>(function: F) -> Self
where F: Fn(DynBuffer<'_>, DynBufferMut<'_>) + Sync + 'a,

Define an operation using a closure. The operation must be both associative and commutative.

This is a more readable shorthand for the new method. Refer to new for more information.

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

pub fn new<F>(commute: bool, function: F) -> Self
where F: Fn(DynBuffer<'_>, DynBufferMut<'_>) + Sync + 'a,

Creates an associative and possibly commutative operation using a closure.

The closure receives two arguments invec and inoutvec as dynamically typed buffers. It shall set inoutvec to the value of f(invec, inoutvec), where f is a binary associative operation.

If the operation is also commutative, setting commute to true may yield performance benefits.

Note: If the closure panics, the entire program will abort.

§Standard section(s)

5.9.5

Source

pub unsafe fn from_raw<T: 'a>(op: MPI_Op, anchor: Box<T>) -> Self

Creates a UserOperation from raw parts.

Here, anchor is an arbitrary object that is stored alongside the MPI_Op. This can be used to attach finalizers to the object.

§Safety

MPI_Op must not be MPI_OP_NULL

Trait Implementations§

Source§

impl<'a> AsRaw for UserOperation<'a>

Source§

type Raw = *mut ompi_op_t

The raw MPI C API type
Source§

fn as_raw(&self) -> Self::Raw

The raw value
Source§

impl<'a> Debug for UserOperation<'a>

Source§

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

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

impl<'a> Drop for UserOperation<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, 'b> Operation for &'b UserOperation<'a>

Source§

fn is_commutative(&self) -> bool

Returns whether the operation is commutative. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for UserOperation<'a>

§

impl<'a> !RefUnwindSafe for UserOperation<'a>

§

impl<'a> !Send for UserOperation<'a>

§

impl<'a> !Sync for UserOperation<'a>

§

impl<'a> Unpin for UserOperation<'a>

§

impl<'a> !UnwindSafe for UserOperation<'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,

Source§

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,

Source§

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

Source§

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>,

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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.