commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ole Ersoy <ole.er...@gmail.com>
Subject Re: [math] Matrix parallel operations
Date Sun, 03 Jan 2016 05:29:17 GMT
Hi Otmar,

On 01/02/2016 10:33 AM, Otmar Ertl wrote:
> On Sat, Jan 2, 2016 at 4:38 AM, Ole Ersoy <ole.ersoy@gmail.com> wrote:
>> Hi,
>>
>> Hope ya'll are having an awesome new year!
>>
>> Some matrix operations, like createRealIdentityMatrix can be turned into one
>> liners like this:
>>
>>         IntStream.range(0, dimension).forEach(i -> m.setEntry(i, i, 1.0));
>>
>> And can be performed in parallel like this:
>>          IntStream.range(0, dimension).parallel().forEach(i -> m.setEntry(i,
>> i, 1.0));
>>
>> Applying that approach in general we could probably create a
>> ParallelXxxRealMatrix fairly easily.   Just thought I'd float the idea.
>>
>> Cheers,
>> Ole
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
> Once we go for Java 8, yes. However, all these constructs have some
> overhead. I doubt that the naive parallelization using parallel() is
> faster than the sequential counterpart, especially for operations such
> as matrix initializations.
I'm sure it depends...But just to find out whether there is any merit to it I ran the identity
matrix code single threaded and parallel (With JMH), and these were the results (On my HP
Envy laptop 8 cores):

# Run complete. Total time: 00:14:08

Benchmark                          Mode  Cnt      Score     Error Units
MyBenchmark.parallelIdentity      thrpt  200  18875.739 ± 400.382 ops/s
MyBenchmark.singleThreadIdentity  thrpt  200  11046.079 ± 130.713 ops/s

So almost twice the throughput with parallel().  This was on a 20K X 20K matrix.  I'll paste
the test code at the bottom.

>   A more efficient parallel implementation
> would require the definition of a Spliterator that divides an
> operation into less but larger chunks of work in order to amortize
> synchronization costs. In general, the implementation of efficient and
> well scaling parallel matrix operations requires more work than
> writing just a single line of code.
I'm sure you are right.  I'm going to test array based matrix vector multiplication next.
 I'm curious to see what happens once some basic operations are added.

Cheers,
Ole


public class IdentityBenchmark {

     @State(Scope.Thread)
     public static class Identity {
         public int dimension = 20000;
         public double[][] m = new double[dimension][dimension];
     }

     @Benchmark
     public void singleThreadIdentity(Identity m) {
         IntStream.range(0, m.dimension).forEach(i -> m.m[i][i] = 1.0);
     }

     @Benchmark
     public void parallelIdentity(Identity m) {
         IntStream.range(0, m.dimension).parallel().forEach(i -> m.m[i][i] = 1.0);
     }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message