bugGNU Octave - Bugs: bug #46830, Multiplication about 4x slower...


bug #46830: Multiplication about 4x slower than Matlab

Submitted by:  Ceral Paquet <octavebugs>
Submitted on:  Wed 06 Jan 2016 10:03:28 AM UTC  
Category:  Performance Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Feature Request
Status:  Works For Me Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  4.2.0 Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Mon 21 Nov 2016 11:45:26 AM UTC, comment #7: 

Another benchmark:

Windows 7, 64 bit, i7-2620M (2 cores, 4 threads)

Octave 4.2.0, 32 bit

a = rand (6000);
tic; a * a; toc
Elapsed time is 21.4271 seconds.

utilizing 4 threads

a = rand (6000);
tic; a .* a; toc
Elapsed time is 0.116012 seconds.

utilizing 1 thread

Matlab R2015b, 64bit

a = rand (6000);
tic; a * a; toc
Elapsed time is 13.481621 seconds.

utilizing 2 threads

a = rand (6000);
tic; a .* a; toc
Elapsed time is 0.097478 seconds.

utilizing 2 threads

So, for me:
1) Both Octave and Matlab use parallelization, to a greater or lesser extent
2) Octave eats +50% runtime and +100% resources when multiplying matrices. => Maybe here, some improvement might be achieved be means of using other library functions, but not "4x slower" as the ticket is saying.
3) When doing element-wise multiplication, both are on a par with runtime and Octave is saving resources. This seems to be consistent with the reports of Philip and Marco.
4) No clue about the GPU
Also, it may be that a bigger difference can be seen when using 6 CPU cores (as Ceral has reported) as compared to 2 CPU cores on my machine. A benchmark with varying the number of available CPU cores might be helpful.

Armin M├╝ller <arm_in>
Thu 17 Nov 2016 12:00:28 AM UTC, comment #6: 

Updating release to 4.2.0. I have no Matlab to compare with, but I see no difference on my system between 3.6.4 and 4.2.0, so I can only assume Octave's performance has not changed relative to itself.

We have some here saying that Octave is significantly slower and single-threaded while Matlab parallelizes the operations, and we have some saying there is no significant difference. Can we at least agree on whether there is a problem in this bug report, what the problem is, and whether we plan on doing anything about it?

Mike Miller <mtmiller>
Project Administrator
Tue 12 Jan 2016 10:35:44 PM UTC, comment #5: 

FWIW, with Matlab r2016a prerelease I see that it uses all four CPU cores (of my i5 PC with 8 GB RAM) when doing

a = rand (1.5e4);
tic; a * a; toc
Elapsed time is 34.337681 seconds.

but at most two cores (~50 % CPU usage) with

a = rand (1.5e4);
a .* a;
Elapsed time is 0.539022 seconds.

(Octave-4.1.0+ needs ~42 sec and 0.7 sec, resp. and Matlab makes the system fans clearly emit more noise with a * a.  AFAIK Matlab also invokes the GPU.)

All in all I'd conclude that Octave doesn't behave much differently from Matlab as regards CPU usage, but might be a little slower as it doesn't use the GPU.

Philip Nienhuis <philipnienhuis>
Project Member
Tue 12 Jan 2016 12:15:28 PM UTC, comment #4: 

For the test with .*, I see both Octave and Matlab at about 0.4 seconds and about 1.0 second with 5000x5000 matrices.

Marco Caliari <caliari>
Project Member
Mon 11 Jan 2016 05:23:46 PM UTC, comment #3: 

The BLAS function DAXPY and similar could be used for the element-wise addition and subtraction operations and DDOT and similar could be used for the element-by-element multiplication operations. For the ./ et .^ operators I don't see a BLAS function that could be used


Wed 06 Jan 2016 04:03:59 PM UTC, comment #2: 

Octave doesn't use BLAS for element-by-element operations as I don't think those are BLAS operations.

John W. Eaton <jwe>
Project Administrator
Wed 06 Jan 2016 10:10:31 AM UTC, comment #1: 

Looking at the top command while running, it's clear that Matlab is using all CPUs for .* wheras Octave is using just one. There are 6 CPUs on my machine.

If I change the .* to a * (matrix multiply) then top shows all the CPUs are being used and the performance is the same.

Ceral Paquet <octavebugs>
Wed 06 Jan 2016 10:03:28 AM UTC, original submission:  

The following code is much slower in Octave than Matlab. I have run it on 2 different machines+verions: v3.81 32-bit from the Ubuntu repo and v4.01 64-bit compiled locally with openblas. Sorry I don't know what package implements the .* operator.

function hello()

tic;for k=1:20;C=A.*B;end;toc


>> hello

Elapsed time is 0.924918 seconds.

>> hello

Elapsed time is 0.935749 seconds.

>> hello

Elapsed time is 0.95104 seconds.


>> hello

Elapsed time is 0.213288 seconds.

>> hello

Elapsed time is 0.214244 seconds.

>> hello

Elapsed time is 0.214326 seconds.

Ceral Paquet <octavebugs>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by arm_in (Posted a comment)
  • -email is unavailable- added by caliari (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by octavebugs (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-01-24 mtmiller Carbon-CopyRemoved 80942 => -
    2016-11-17 mtmiller Release4.0.1-rc1 => 4.2.0
    2016-01-12 caliari StatusPostponed => Works For Me
    2016-01-08 siko1056 Severity3 - Normal => 1 - Wish
        Item GroupNone => Feature Request
        StatusNone => Postponed
        Operating SystemGNU/Linux => Any
    2016-01-06 jwe CategoryNone => Performance

    Back to the top

    Powered by Savane 3.5