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

Parallel-For jobs #25

Merged
merged 11 commits into from
Oct 22, 2023
Merged

Parallel-For jobs #25

merged 11 commits into from
Oct 22, 2023

Conversation

LilithSilver
Copy link
Collaborator

@LilithSilver LilithSilver commented Oct 21, 2023

Relies on #24 and predecessors, so let's resolve those first.

This PR implements IJobParallelFor with a basic work-stealing algorithm. The underlying data structure is like Chase-Lev's work-stealing deque, except I made a special version that just operates on a Range of ints, giving both O(1) time and space complexity.

The work-stealing algorithm itself is nothing special; thieves just try until all the deques are empty and then give up. There's no yielding or sleeping because we know no parallel ranges can spawn other parallel ranges, so we know we want to use the full system resources.

Here's a simple increment-counter benchmark:

Method Threads MaxConcurrentJobs Mean Error StdDev Allocated
BenchmarkForLoop 0 32 68.05 ms 0.191 ms 0.149 ms 600 B
BenchmarkStandardParallelFor 0 32 446.61 ms 0.249 ms 0.233 ms 150080 B
BenchmarkParallelFor 0 32 467.79 ms 6.362 ms 5.640 ms 600 B

And here's testing multiplying a 1024x1024 matrix (an actually difficult task):

Method Threads MaxConcurrentJobs Mean Error StdDev Median Allocated
BenchmarkForLoop 0 32 273.91 ms 0.750 ms 0.701 ms 274.07 ms 600 B
BenchmarkStandardParallelFor 0 32 34.35 ms 0.167 ms 0.148 ms 34.35 ms 5496 B
BenchmarkParallelFor 0 32 47.16 ms 2.196 ms 6.474 ms 51.10 ms 600 B

As you can see, it hits in a similar ballpark to Parallel.For. It's a bit slower, but I think it's "good enough" and I'm not sure how to improve it further.

@LilithSilver LilithSilver requested a review from genaray October 21, 2023 20:55
@LilithSilver LilithSilver changed the title Parallel jobs Parallel-For jobs Oct 21, 2023
@genaray genaray merged commit 5707dac into genaray:master Oct 22, 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.

2 participants