[concurrency-interest] question from new-user/instructor: "x.fork(); x.join()" vs. x.compute()

Doug Lea dl at cs.oswego.edu
Sun Mar 14 19:37:41 EDT 2010

On 03/14/10 19:13, Dan Grossman wrote:
> Why am I seeing "x.fork(); x.join()" causing a trivial program to take
> about
> 40x longer than the same program written using x.compute()?

Short version:
(1) Because there is nothing that does this optimization for you,
So you must hand-optimize this case.
(2) Because of big warm-up effects.

> Long version:
> Who Should I Ask:

This list is a good place.

> Why is there such a difference in these two versions?

Try putting your test in a loop and repeating.
For me (using current internal snapshot on an Intel i7);
with FORK true, I get on the first iteration:
   parallel: 729 sequential: 38
and the 20th
   parallel: 26 sequential: 11
With FORK false, first:
   parallel: 177 sequential: 38
   parallel: 7 sequential: 11

Which reflects that that after warmup, "fork(); join()" is around
4X-10X the overhead of just a straight method call. But it takes a while
for a JIT to decide to compile the workstealing code, so the first
runs are terrible. Yes, this is a problem. We are working on it.
You might have seen even more extreme results because current
uncommitted version addresses some of this.

Hope this helps.


More information about the Concurrency-interest mailing list