Fork/Join in slow motion
Have you ever wondered how fork/join algorithm really works? You can read a description
but it is much better to actually see how the tasks are split, how the threads
process them, how work stealing works and so on.
And that’s exactly what we have done on the last
GPars Hackathon. We have created demo that visualizes fork/join in slow motion.
Source codes are available here (Groovy, Java). The demo was brought to you by me, Jety and Václav.
Published at DZone with permission of its author, Lukas Krecan.(alternatively you can download and execute this jar)
You can notice several things
- A thread stays in its column. Threads do not compete, each of them works on its part of the problem.
- If a thread is forced to steal some work it takes a big chunk so it does not have to go stealing soon again.
- It does not run in the sandbox. Th jsr166y library uses sun.misc.Unsafe which is not part of public SDK API. That’s why you have to trust my self-signed certificate.
Source codes are available here (Groovy, Java). The demo was brought to you by me, Jety and Václav.
(1 vote)
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Hamlet D'Arcy replied on Tue, 2011/03/29 - 12:57am
This is actually pretty interesting. Turn the speed up, the number of threads up, and random data... and you start to see surprising patterns in how work is completed.
Also, the whole demo is only 250 lines of code. Check out the source: http://git.codehaus.org/gitweb.cgi?p=gpars.git;a=blob_plain;f=src/test/groovy/groovyx/gpars/samples/forkjoin/DemoVisualForkJoinMergeSort.groovy;hb=373d0bad2a0ce2521cd36055e475cb4f47e7686c
Kamil Szabo replied on Tue, 2011/03/29 - 2:08am
Hamlet D'Arcy replied on Tue, 2011/03/29 - 3:11am
in response to:
Kamil Szabo
Fork/Join absolutely 100% helps Java code run on more cores in parallel. What article did you read that said Fork/Join did not help with parallelization?
Martijn & Ben V... replied on Tue, 2011/03/29 - 6:27am
Ben Anderson replied on Tue, 2011/03/29 - 10:31am
Lukas Krecan replied on Wed, 2011/03/30 - 2:37am
Liezel Jane Jandayan replied on Mon, 2011/09/19 - 1:18am