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

kabutz duke at openjdk.java.net
Thu Dec 16 06:00:57 UTC 2021


On Thu, 16 Dec 2021 01:01:33 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Inside the constructor would not work, since we do not construct RecursiveOp for all the tasks. However, I have incremented the parameter depth. I don't like changing parameters inside methods, but since I'm doing it where it is being used, I feel that the code is now better than before. Thanks for the suggestion.
>
> I am confused by "we do not construct RecursiveOp for all the tasks", since each call to `RecursiveOp.multiply/square` constructs a new object that is an instance of `RecursiveOp`. 
> 
> Your approach looks good.

var v0_task = RecursiveOp.multiply(a0, b0, parallel, depth); // Here we make a new RecursiveOp for the multiply
        da1 = a2.add(a0);
        db1 = b2.add(b0);
        var vm1_task = RecursiveOp.multiply(da1.subtract(a1), db1.subtract(b1), parallel, depth); // Here also
        da1 = da1.add(a1);
        db1 = db1.add(b1);
        var v1_task = RecursiveOp.multiply(da1, db1, parallel, depth); // And here
        v2 = da1.add(a2).shiftLeft(1).subtract(a0).multiply( // Here we call multiply() directly, without the RecursiveOp
             db1.add(b2).shiftLeft(1).subtract(b0), true, parallel, depth);
        vinf = a2.multiply(b2, true, parallel, depth); // Again, we call multiply() directly
        v0 = v0_task.join();
        vm1 = vm1_task.join();
        v1 = v1_task.join();

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

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


More information about the core-libs-dev mailing list