答复: Demo for Parallel Core Collection API

Tristan Yan tristan.yan at oracle.com
Tue Feb 4 17:20:33 UTC 2014


Thank you Paul.  I was told maybe we will target this on 8u20 if we can't catch 8. Let's do the open review first.

http://cr.openjdk.java.net/~tyan/JDK-8033358/webrev.02/

Fibonacci:
Update as you suggested. Test shows parallel version is faster than sequential version when the input is greater than 100,000.

ImageTransform
Inner parallel was eliminated. Also BufferedImage.set is a thread safe method.

MonteCarloPI
Unused hit method was removed.

RandomPrimeNumber
It's changed into ProbablePrimeNumber. Following your suggestion to use BigInteger.probablePrime method.

Thank you
Tristan




-----邮件原件-----
发件人: Paul Sandoz 
发送时间: Tuesday, February 04, 2014 5:34 PM
收件人: Tristan Yan
抄送: core-libs-dev at openjdk.java.net; Aleksandre Iline; Mikhail Kondratyev
主题: Re: Demo for Parallel Core Collection API

On Feb 4, 2014, at 2:58 AM, Tristan Yan <tristan.yan at oracle.com> wrote:
> Hi Paul
> I know this may be a little bit late.

Yes, likely too late... (see below).


> But I am still asking you review this.
> 
> http://cr.openjdk.java.net/~tyan/JDK-8033358/webrev.01/
> 
> This is a whole demo code include the stream demo code you reviewed before also included parallel part. There is one other parallel demo that Paul has already pushed.
> Could you please review it again?

Fibonacci

- There is no parallel execution; one can write as follows for better splitting:

        return IntStream.range(0, n).mapToObj(i -> matrix).
                parallel().
                reduce(Fibonacci::times).
                get();

- While the approach is interesting (elegant in terms of the reduction) one is not likely to observe any speed up (did you measure?) since the long value will overflow on the 93rd number [1]. You would need to use BigInteger and a larger number of iterations.


ImageTransform

- In rotate/shift/zoom/invert the inner range (over height) should not be parallel, it's just gonna fight for resources with the outer range (over width).

- It's not entirely clear to me if BufferedImage is thread safe to concurrently set the pixels


MonteCarloPI

- hit() method is no longer used.


RandomPrimeNumber

- better to use ThreadLocalRandom or SplittableRandom, as both of those produce higher quality sequences of random numbers.

- i don't think this example has much value as there are better ways to determine primes. As i have said before, if you want to show a simple example it is better to show the parallel generation of probable primes using BigInteger.

--

I am sorry to have to say this, i know if you have worked on this for a while, but i think this is now too late to go through another round of reviews.

Paul.

[1] Think rabbits!
http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibtable.html
You can think





More information about the core-libs-dev mailing list