[concurrency-interest] jsr166y.forkjoin API comments

David J. Biesack David.Biesack at sas.com
Mon Jan 28 15:15:58 EST 2008


I wrote:

> Having written this example, I come away with two (new!) API comments
> which I'll post separately.

Here is the first observation.

As can be seen with the Matrix Multiplication example at http://artisans-serverintellect-com.si-eioswww6.com/default.asp?W40 , sometimes you want fork/join but you don't have an array to operate on; you just have a set of indices. In the example, I create a ParallelArray but don't use it; the data already exists in double[][] arrays. Hence the internal allocation of the Object[] array is wasted.

I could have created a ParallelArray<double[]> but this would have been misleading since the algorithm is not structured that way. That is, for the original sequential algorithm,


        for (int j = 0; j < n; j++) {
            for (int i = 0; i < m; i++) {
                final double[] Arowi = a[i];
                double s = 0;
                for (int k = 0; k < n; k++) {
                    s += Arowi[k] * b[k][j]; // A[i][k] * B[k][j]
                }
                c[i][j] = s;
            }
        }

where j is the outer loop index, there is not an array that is referenced via array[j]. Thus, using ForkJoin is slightly more awkward than it needs to be for this pretty basic operation.

I don't know if there is a solution other than adding a new create() method which defers allocating the internal array until and only if it is needed (or maybe not at all, and it's a programming error to use the wrong factory if you really wish to replace/generate values.

-- 
David J. Biesack     SAS Institute Inc.
(919) 531-7771       SAS Campus Drive
http://www.sas.com   Cary, NC 27513



More information about the Concurrency-interest mailing list