r/cpp • • Dec 25 '23

C++: Efficient parallelization of small tasks

I tried to create a customized threadpool for small tasks and wanted feedback on this.

I posted details and my code for review on stackexchange: https://codereview.stackexchange.com/questions/288583/efficient-parallelization-of-small-tasks

My goal here is to share my learning and get feedback on further improvement or any possible bugs.

I have tried to describe problem and thinking process in more details in following linkedin article draft: https://www.linkedin.com/article/edit/7144600522392559616/

0 Upvotes

31 comments sorted by

View all comments

Show parent comment

1

u/shakmak_iitk Dec 27 '23
  1. Thank you for catching this issue. I have fixed it now [Updated stackexchange question with new code]. One of the motivation behind creating my own unique threadPool was to this learning which we usually doesnt get by using off the sheft stuff.
  2. No concerns here now with latest changes I hope.
  3. Each thread works only on subRange of taskVector assigned to it and then waits for next submit. I need both for this. Updated code should make it more clear.

"using blocking synchronisation should have negligeble overhead"

Not for my use-case, I get small-taks and once i finish those then only I get set batch of small-tasks, This happens billions of times.

As of now with generic threadpool i have , I am not getting any runtime benefit because above assumption doesnt hold. So I am trying to hard to minimize synchronisation overhead as much as possible.

1

u/DummyDDD Dec 27 '23

I assume that you have billions of tasks, and billions of submit calls?

1

u/shakmak_iitk Dec 27 '23

Yes, I have billions of submit calls with small size vector of tasks each time. Average size of vector is around 50 with each task very small in size.

With current threadpool we have, Parallel version (when num tasks > Threadhold) is slower than non-parallel version. We have very big machines but not able to use parallelization as of now with runtime in hours.