rayon-rs / rayon

Rayon: A data parallelism library for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential to modify ordering for split_count and tour_counter

wang384670111 opened this issue · comments

let update = self
.split_count
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |c| c.checked_sub(1));

SeqCst is overly restrictive. I believe that the ordering can be appropriately modified.

In par_bridge model, I believe that split_count is just a counter across threads and does not synchronize with other locals. Therefore, using Relaxed ordering should suffice.

let counter = self.tour_counter.fetch_add(1, Ordering::SeqCst);

Similarly, In solver model, tour_counter is just a counter across threads, using Relaxed ordering should suffice.

(happy to make a PR if this looks reasonable)

It's been this way in par_bridge since it was first added in #550, but I don't think we paid much attention to that ordering. I agree that Relaxed should be fine, but I also think it won't make much difference, as this only executes once per thread for a given par_bridge. The real contention comes when they all wait on the same Mutex<Iter>.

The tsp counter is fine to change too. You're welcome to make a PR!

Related Link for PR:
#1140