Demo for Parallel Core Collection API

Paul Sandoz paul.sandoz at
Fri Dec 20 17:25:00 UTC 2013

Hi Tristan,

Thanks, I need to look at this in more detail, but here are some quick comments.

- recommend you try and avoid using limit with parallel ops, for example the Pi example cam be reformulated as:

       long M = LongStream.range(0, N).parallel().filter(sr -> {
           double x = ThreadLocalRandom.current().nextDouble(-1, 1);
           double y = ThreadLocalRandom.current().nextDouble(-1, 1);

           return x * x + y * y < R * R;  // Don't use need to use sqrt
      double pi = (M / N) * 4.0;

the Primes example could be reformulated as:

   LongStream.range(0, limit).parallel().map(/odd values/).filter(RandomPrimeNumber::isPrime).findAny();

you don't need to declare unordered() since findAny implicitly makes the stream unordered by definition.

The key message here is range has better decomposition characteristics than generate or iterate.

More later, probably after the break,

On Dec 19, 2013, at 1:16 PM, Tristan Yan <tristan.yan at> wrote:

> Hi Paul And Everyone
> Sorry for getting back late.
> I took Paul's suggestion and have written other two demos which presents usage of parallel computation. One is using Monte-Carlo to calculate value of PI. Other is find a big prime by given length. Please review it.
> There is another demo which present mandelbrot set was designed Alexander Kouznetsov has been already in reviewing. It's not my code review request.
> Thank you very much
> Tristan

More information about the core-libs-dev mailing list