Skip to main content

ibverbs_rs/network/
polling_scope.rs

1use crate::channel::{PollingScope, ScopeError};
2use crate::ibverbs::protection_domain::ProtectionDomain;
3use crate::network::Node;
4
5impl Node {
6    /// Opens a polling scope that automatically polls all outstanding work requests when it ends.
7    ///
8    /// See [`Channel::scope`](crate::channel::Channel::scope) for details on the scoping mechanism.
9    pub fn scope<'env, F, T, E>(&'env mut self, f: F) -> Result<T, ScopeError<E>>
10    where
11        F: for<'scope> FnOnce(&mut PollingScope<'scope, 'env, Node>) -> Result<T, E>,
12    {
13        PollingScope::run(self, f)
14    }
15    /// Opens a polling scope that enforces manual polling of all work requests.
16    ///
17    /// See [`Channel::manual_scope`](crate::channel::Channel::manual_scope) for details.
18    pub fn manual_scope<'env, F, T, E>(&'env mut self, f: F) -> Result<T, E>
19    where
20        F: for<'scope> FnOnce(&mut PollingScope<'scope, 'env, Node>) -> Result<T, E>,
21    {
22        PollingScope::run_manual(self, f)
23    }
24}
25
26impl<'scope, 'env> PollingScope<'scope, 'env, Node> {
27    /// Returns a reference to the shared [`ProtectionDomain`].
28    pub fn pd(&self) -> &ProtectionDomain {
29        self.inner.pd()
30    }
31
32    /// Returns the total number of nodes in the network.
33    pub fn world_size(&self) -> usize {
34        self.inner.world_size()
35    }
36
37    /// Returns this node's rank.
38    pub fn rank(&self) -> usize {
39        self.inner.rank()
40    }
41}