Best way to pass data to processes

Hello, I want to parallelize an iteration but i don't know what is the best way to do this. Using locks the performance is terrible.

fn func(mut data: &mut Datatype) {
        (0..N)
            .into_par_iter()
            .for_each(|j| {
                other_func(&mut data);
            });

      (0..N)
            .into_par_iter()
            .for_each(|j| {
                other_func(&mut data);
            });
}

This is an example code, but i need to avoid doing data.par_iter_mut() because i don't need to parallelize everything in data.

Would you recommend something ? Thanks a lot.

What are you locking on? You need to be able to distribute work that can be done multithreaded, so if you're locking on the same data structure in each thread you're essentially running sequentially.

Your sample code doesn't work, since for_each takes Fn and not FnMut. If you can post what you want to do in other_func, there might be a way of splitting the work up that doesn't require &mut of the whole Datatype.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.