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

Add "dynamic" parallelization strategies. #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gonnet
Copy link

@gonnet gonnet commented Sep 4, 2024

This change adds the following parallelization functions:

  • pthreadpool_parallelize_1d_dynamic,
  • pthreadpool_parallelize_2d_dynamic_1d,
  • pthreadpool_parallelize_2d_dynamic, and
  • pthreadpool_parallelize_3d_dynamic_2d.

These functions are similar to the pthreadpool_parallelize_Xd_tile_Yd functions, but differ in that the tile_* values are not bounds, but instead preferred multiples.

For example, pthreadpool_parallelize_1d_dynamic(threadpool, task, context, range, tile, flags) calls the user-provided task function

task(context, offset, count)

where

  • offset is in the range [0, range) and an integer multiple of tile, and
  • count is an integer multiple of tile unless offset + count = range.

The tile parameter is understood as a preferred multiple of indices, and not as an upper bound.

The counts are chosen such as to minimize the number of calls to task while still balancing the workload across all threads.

Under the hood, each thread tries to reserve a "chunk" of tiles corresponding to

size_t chunk_size = max(num_tasks / (2 * num_threads), 1);
chunk_size = ((chunk_size + tile - 1) / tile) * tile;

i.e. the number of remaining tasks divided by 2x the number of threads, rounded up to the next multiple of tile. This balances well provided the speed difference between the fastest and slowest threads does not exceed a factor of 2.

@gonnet
Copy link
Author

gonnet commented Sep 10, 2024

Hi @Maratyszcza,

Please let me know if you have the time to review this PR or not, or whether you are still accepting PRs or not ☺️

Cheers, Pedro

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