pub trait ForEachNodeParallelByPartitionOp<NI>where
    NI: Idx,{
    // Required method
    fn for_each_node_par_by_partition<T, F>(
        &self,
        partition: &[Range<NI>],
        node_values: &mut [T],
        node_fn: F
    ) -> Result<(), Error>
       where T: Send,
             F: Fn(&Self, NI, &mut T) + Send + Sync;
}
Expand description

Call a particular function for each node with its corresponding state in parallel based on a partition.

Required Methods§

source

fn for_each_node_par_by_partition<T, F>( &self, partition: &[Range<NI>], node_values: &mut [T], node_fn: F ) -> Result<(), Error>where T: Send, F: Fn(&Self, NI, &mut T) + Send + Sync,

For each node calls node_fn with the node and its corresponding mutable state in parallel, using partition as a parallelization hint.

For every node n in the graph node_fn(&self, n, node_values[n.index()]) will be called.

node_values must have length exactly equal to the number of nodes in the graph.

The parallelization will be implemented such that the work for a set of nodes represented by each range in partition will correspond to a task that will run in a single thread.

Example
let graph: DirectedCsrGraph<u32> = GraphBuilder::new()
    .edges(vec![(0, 1), (0, 2), (1, 2)])
    .build();
let mut node_values = vec![0; 3];
let partition: Vec<Range<u32>> = graph.out_degree_partition(num_cpus::get());

graph.
    for_each_node_par_by_partition(&partition, &mut node_values, |g, node, node_state| {
        *node_state = g.out_degree(node);
    });

assert_eq!(node_values[0], 2);
assert_eq!(node_values[1], 1);
assert_eq!(node_values[2], 0);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<NI, G> ForEachNodeParallelByPartitionOp<NI> for Gwhere NI: Idx, G: Graph<NI> + Sync,