RFR: JDK-8277175 : Add a parallel multiply method to BigInteger [v5]

kabutz duke at openjdk.java.net
Wed Dec 15 08:53:59 UTC 2021


On Tue, 30 Nov 2021 23:16:20 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> kabutz has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Made forkOrInvoke() method protected to avoid strange compiler error
>
> src/java.base/share/classes/java/math/BigInteger.java line 1875:
> 
>> 1873:         private static final int PARALLEL_FORK_THRESHOLD = Integer.getInteger(
>> 1874:                 "java.math.BigInteger.parallelForkThreshold",
>> 1875:                 (int) Math.ceil(Math.log(Runtime.getRuntime().availableProcessors()) / Math.log(2)));
> 
> We can simplify to `32 - Integer.numberOfLeadingZeros(ForkJoinPool.getCommonPoolParallelism() - 1))`.
> 
> `ForkJoinPool.getCommonPoolParallelism()` is guaranteed to return a value `> 0`

`ForkJoinPool.getCommonPoolParallelism() ` cannot distinguish between 0, 1, and 2 active processors.  In the `java.util.stream.AbstractTask` class they calculate the number of leaves based on this with << 2. However, there is always the possibility that someone launches the parallel stream inside another FJP, so they check for that as well. It does complicate things a bit, but at the same time, means we have one less environment variable. And if it becomes an issue (which I doubt), then we can always add it later. Will work on this a bit.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6409


More information about the core-libs-dev mailing list