Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallelize workload imbalance #7

Closed
wants to merge 1 commit into from
Closed

Fix parallelize workload imbalance #7

wants to merge 1 commit into from

Conversation

mratsim
Copy link

@mratsim mratsim commented Jun 12, 2023

This fixes the parallel workload imbalance mentioned in my PSE/Taiko codebase review.

Currently if we take 40 items divided into 12 threads (AMD Ryzen 7800X, Apple M2 Pro or Intel i5-12600) the partitioning will lead to 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7 = 3*11 + 7 = 40. The “remainder” thread will have 2.33x more work to do.

This can be quite extreme for example if we have 351 items to split on 32 cores, 351/32 = 10.96, rounded to 10 with integer division. 10*31 = 310, the last core needs to process 41 items, 4.1x more than the others.

This ensures whatever the number of items and the number of threads, the workload varies by at most 1.

This probably explains why not all cores are used while benchmarking (benchmarks TODO).

Unsafe

Note: I'm not familiar with Rust standard library and parallelism development since October 2016 (my last foray into writing Rust programs).
I've looked into:

Note of the chunking routines provides balanced partitioning of a range.

  • Either the last chunk can be extremely large like with the current usage of chunks_mut
  • or it's not returned like in array_chunks and requires a separate remainder call
  • or we get more chunks than our number of threads like with as_chunks

I might very well have missed something though.

@mratsim
Copy link
Author

mratsim commented Jun 12, 2023

Upstreamed at privacy-scaling-explorations#186

@mratsim mratsim closed this Jun 12, 2023
@mratsim mratsim mentioned this pull request Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant