CPU time, Octave vs MATLAB

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

CPU time, Octave vs MATLAB

Rory Conolly
I have a program that describes biological mechanisms of cancer. Running the code in MATLAB takes 112 minutes. The almost identical code in Octave takes about 10 hr, so about 5 times slower. Is this an expected difference between Octave and MATLAB or more likely due to something in my code? Code is hundreds of lines over several files.

- Rory


Reply | Threaded
Open this post in threaded view
|

Re: CPU time, Octave vs MATLAB

siko1056
On 3/10/20 9:39 PM, Rory Conolly wrote:
> I have a program that describes biological mechanisms of cancer. Running
> the code in MATLAB takes 112 minutes. The almost identical code in
> Octave takes about 10 hr, so about 5 times slower. Is this an expected
> difference between Octave and MATLAB or more likely due to something in
> my code? Code is hundreds of lines over several files.
>
> - Rory
>

Dear Rory,

Unless you present (a meaningful portion of) your code, it is fortune
telling and blind guessing what could be wrong.  Most likely your code
is not properly vectorized [1] and uses lots of nested loops, e.g.

for k = 1:P
  for i = 1:M
    for j = 1:N
      A(i,j) = A(i,j) + B(i,j);
    endfor
  endfor
endfor

You can make use of profiling [2] to find the bottlenecks.

HTH,
Kai

[1] https://octave.org/doc/v5.2.0/Basic-Vectorization.html
[2] https://octave.org/doc/v5.2.0/Profiling.html


Reply | Threaded
Open this post in threaded view
|

Re: CPU time, Octave vs MATLAB

Rory Conolly


On Tue, Mar 10, 2020 at 10:08 AM Kai Torben Ohlhus <[hidden email]> wrote:
On 3/10/20 9:39 PM, Rory Conolly wrote:
> I have a program that describes biological mechanisms of cancer. Running
> the code in MATLAB takes 112 minutes. The almost identical code in
> Octave takes about 10 hr, so about 5 times slower. Is this an expected
> difference between Octave and MATLAB or more likely due to something in
> my code? Code is hundreds of lines over several files.
>
> - Rory
>

Dear Rory,

Unless you present (a meaningful portion of) your code, it is fortune
telling and blind guessing what could be wrong.  Most likely your code
is not properly vectorized [1] and uses lots of nested loops, e.g.

for k = 1:P
  for i = 1:M
    for j = 1:N
      A(i,j) = A(i,j) + B(i,j);
    endfor
  endfor
endfor

You can make use of profiling [2] to find the bottlenecks.

HTH,
Kai

[1] https://octave.org/doc/v5.2.0/Basic-Vectorization.html
[2] https://octave.org/doc/v5.2.0/Profiling.html


Kai, thanks for your input. My question is more about the relative speed of Octave vs MATLAB. My code was originally developed in MATLAB and is vectorized. The code reads parameter values from an Excel file. The Octave call to Excel requires the file extension while the MATLAB call does not. So that’s the only modification of the code running in Octave. So the two codes are pretty much identical, but the Octave code runs much more slowly. Happy to provide the code but it’s in several files and probably a thousand or more lines. 

 


Reply | Threaded
Open this post in threaded view
|

Re: CPU time, Octave vs MATLAB

Ian McCallion
On Tue, 10 Mar 2020 at 14:31, Rory Conolly <[hidden email]> wrote:

>
>
>
> On Tue, Mar 10, 2020 at 10:08 AM Kai Torben Ohlhus <[hidden email]> wrote:
>>
>> On 3/10/20 9:39 PM, Rory Conolly wrote:
>> > I have a program that describes biological mechanisms of cancer. Running
>> > the code in MATLAB takes 112 minutes. The almost identical code in
>> > Octave takes about 10 hr, so about 5 times slower. Is this an expected
>> > difference between Octave and MATLAB or more likely due to something in
>> > my code? Code is hundreds of lines over several files.
>> >
>> > - Rory
>> >
>>
>> Dear Rory,
>>
>> Unless you present (a meaningful portion of) your code, it is fortune
>> telling and blind guessing what could be wrong.  Most likely your code
>> is not properly vectorized [1] and uses lots of nested loops, e.g.
>>
>> for k = 1:P
>>   for i = 1:M
>>     for j = 1:N
>>       A(i,j) = A(i,j) + B(i,j);
>>     endfor
>>   endfor
>> endfor
>>
>> You can make use of profiling [2] to find the bottlenecks.
>>
>> HTH,
>> Kai
>>
>> [1] https://octave.org/doc/v5.2.0/Basic-Vectorization.html
>> [2] https://octave.org/doc/v5.2.0/Profiling.html
>
>
>
> Kai, thanks for your input. My question is more about the relative speed of Octave vs MATLAB. My code was originally developed in MATLAB and is vectorized. The code reads parameter values from an Excel file. The Octave call to Excel requires the file extension while the MATLAB call does not. So that’s the only modification of the code running in Octave. So the two codes are pretty much identical, but the Octave code runs much more slowly. Happy to provide the code but it’s in several files and probably a thousand or more lines.

Octave generally is nothing like 5 times slower than Matlab. My own
code for example runs at about the same speed. However I believe
Matlab has worked hard to improve nested loop performance in
particular. Hence Kai's suggestions.

Vectorisation also improves quality and readability. Go for it!

Cheers... Ian


Reply | Threaded
Open this post in threaded view
|

Re: CPU time, Octave vs MATLAB

Ardid, Salva-2
De: Help-octave <help-octave-bounces+salva.ardid=[hidden email]> de part de Ian McCallion <[hidden email]>
Enviat el: dimarts, 10 de març de 2020 10:50
Per a: Rory Conolly <[hidden email]>
A/c: Kai Torben Ohlhus <[hidden email]>; Octave Help <[hidden email]>
Tema: Re: CPU time, Octave vs MATLAB
 
On Tue, 10 Mar 2020 at 14:31, Rory Conolly <[hidden email]> wrote:
>
>
>
> On Tue, Mar 10, 2020 at 10:08 AM Kai Torben Ohlhus <[hidden email]> wrote:
>>
>> On 3/10/20 9:39 PM, Rory Conolly wrote:
>> > I have a program that describes biological mechanisms of cancer. Running
>> > the code in MATLAB takes 112 minutes. The almost identical code in
>> > Octave takes about 10 hr, so about 5 times slower. Is this an expected
>> > difference between Octave and MATLAB or more likely due to something in
>> > my code? Code is hundreds of lines over several files.
>> >
>> > - Rory
>> >
>>
>> Dear Rory,
>>
>> Unless you present (a meaningful portion of) your code, it is fortune
>> telling and blind guessing what could be wrong.  Most likely your code
>> is not properly vectorized [1] and uses lots of nested loops, e.g.
>>
>> for k = 1:P
>>   for i = 1:M
>>     for j = 1:N
>>       A(i,j) = A(i,j) + B(i,j);
>>     endfor
>>   endfor
>> endfor
>>
>> You can make use of profiling [2] to find the bottlenecks.
>>
>> HTH,
>> Kai
>>
>> [1] https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Foctave.org%2Fdoc%2Fv5.2.0%2FBasic-Vectorization.html&amp;data=02%7C01%7Csalva.ardid%40yale.edu%7C749c0743ba544f6b46e708d7c50262a4%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637194486346325825&amp;sdata=7ZA842tIfbCjWRAIbvltWpsEcGVSdYzDxQS7iKT3FEg%3D&amp;reserved=0
>> [2] https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Foctave.org%2Fdoc%2Fv5.2.0%2FProfiling.html&amp;data=02%7C01%7Csalva.ardid%40yale.edu%7C749c0743ba544f6b46e708d7c50262a4%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637194486346325825&amp;sdata=%2Fxs1h0MKPA7ixzy89pkONh5YozIaUXuQh2BvqtIalH0%3D&amp;reserved=0
>
>
>
> Kai, thanks for your input. My question is more about the relative speed of Octave vs MATLAB. My code was originally developed in MATLAB and is vectorized. The code reads parameter values from an Excel file. The Octave call to Excel requires the file extension while the MATLAB call does not. So that’s the only modification of the code running in Octave. So the two codes are pretty much identical, but the Octave code runs much more slowly. Happy to provide the code but it’s in several files and probably a thousand or more lines.

Octave generally is nothing like 5 times slower than Matlab. My own
code for example runs at about the same speed. However I believe
Matlab has worked hard to improve nested loop performance in
particular. Hence Kai's suggestions.

Vectorisation also improves quality and readability. Go for it!

Cheers... Ian


Hi Rory,

To be a bit more specific on this
Matlab has worked hard to improve nested loop performance

The difference between Matlab and Octave here is related to the JIT compiler.


Vectorisation also improves quality and readability. Go for it!

In some cases, I have seen Matlab unvectorized loops working faster than vectorized expressions, so even if you can and further vectorize your code in Octave, you may still see a time difference wrt Matlab.

Moreover, not all nested loops can be avoided, unfortunately. If that would be your case, there's not much you can do about it.

In any case, you may want to check the profilers and see where the bottleneck is.

Best,
Salva


Reply | Threaded
Open this post in threaded view
|

RE: CPU time, Octave vs MATLAB

hjborsje

 

 

From: Ardid, Salva <[hidden email]>
Sent: Tuesday, March 10, 2020 4:22 PM
To: Ian McCallion <[hidden email]>; Rory Conolly <[hidden email]>
Cc: Kai Torben Ohlhus <[hidden email]>; Octave Help <[hidden email]>
Subject: Re: CPU time, Octave vs MATLAB

 

De: Help-octave <[hidden email]> de part de Ian McCallion <[hidden email]>
Enviat el: dimarts, 10 de març de 2020 10:50
Per a: Rory Conolly <[hidden email]>
A/c: Kai Torben Ohlhus <[hidden email]>; Octave Help <[hidden email]>
Tema: Re: CPU time, Octave vs MATLAB

 

On Tue, 10 Mar 2020 at 14:31, Rory Conolly <[hidden email]> wrote:


>
>
>
> On Tue, Mar 10, 2020 at 10:08 AM Kai Torben Ohlhus <[hidden email]> wrote:
>>
>> On 3/10/20 9:39 PM, Rory Conolly wrote:
>> > I have a program that describes biological mechanisms of cancer. Running
>> > the code in MATLAB takes 112 minutes. The almost identical code in
>> > Octave takes about 10 hr, so about 5 times slower. Is this an expected
>> > difference between Octave and MATLAB or more likely due to something in
>> > my code? Code is hundreds of lines over several files.
>> >
>> > - Rory
>> >
>>
>> Dear Rory,
>>
>> Unless you present (a meaningful portion of) your code, it is fortune
>> telling and blind guessing what could be wrong.  Most likely your code
>> is not properly vectorized [1] and uses lots of nested loops, e.g.
>>
>> for k = 1:P
>>   for i = 1:M
>>     for j = 1:N
>>       A(i,j) = A(i,j) + B(i,j);
>>     endfor
>>   endfor
>> endfor
>>
>> You can make use of profiling [2] to find the bottlenecks.
>>
>> HTH,
>> Kai
>>
>> [1] https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Foctave.org%2Fdoc%2Fv5.2.0%2FBasic-Vectorization.html&amp;data=02%7C01%7Csalva.ardid%40yale.edu%7C749c0743ba544f6b46e708d7c50262a4%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637194486346325825&amp;sdata=7ZA842tIfbCjWRAIbvltWpsEcGVSdYzDxQS7iKT3FEg%3D&amp;reserved=0
>> [2] https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Foctave.org%2Fdoc%2Fv5.2.0%2FProfiling.html&amp;data=02%7C01%7Csalva.ardid%40yale.edu%7C749c0743ba544f6b46e708d7c50262a4%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637194486346325825&amp;sdata=%2Fxs1h0MKPA7ixzy89pkONh5YozIaUXuQh2BvqtIalH0%3D&amp;reserved=0
>
>
>
> Kai, thanks for your input. My question is more about the relative speed of Octave vs MATLAB. My code was originally developed in MATLAB and is vectorized. The code reads parameter values from an Excel file. The Octave call to Excel requires the file extension while the MATLAB call does not. So that’s the only modification of the code running in Octave. So the two codes are pretty much identical, but the Octave code runs much more slowly. Happy to provide the code but it’s in several files and probably a thousand or more lines.

Octave generally is nothing like 5 times slower than Matlab. My own
code for example runs at about the same speed. However I believe
Matlab has worked hard to improve nested loop performance in
particular. Hence Kai's suggestions.

Vectorisation also improves quality and readability. Go for it!

Cheers... Ian


Hi Rory,

To be a bit more specific on this

Matlab has worked hard to improve nested loop performance

 

The difference between Matlab and Octave here is related to the JIT compiler.

 

Vectorisation also improves quality and readability. Go for it!

 

In some cases, I have seen Matlab unvectorized loops working faster than vectorized expressions, so even if you can and further vectorize your code in Octave, you may still see a time difference wrt Matlab.

Moreover, not all nested loops can be avoided, unfortunately. If that would be your case, there's not much you can do about it.

In any case, you may want to check the profilers and see where the bottleneck is.

 

Best,

Salva

 

I find that Octave can be 10 – 20 % slower than ML.  One significant exception I found to be the svd.  The default processing in Octave is rather slower than ML, especially when the matrix gets large.  There is a thread about this not that long ago.

 

Henk Borsje



Reply | Threaded
Open this post in threaded view
|

Re: CPU time, Octave vs MATLAB

nrjank
In reply to this post by Rory Conolly

My code was originally developed in MATLAB and is vectorized

If that's the case, I would encourage you to use Octave's profiler and find out what your code is spending time on.  It would be useful if you could to the same with Matlab's code profiler and find where the key differences are. 


Reply | Threaded
Open this post in threaded view
|

Re: CPU time, Octave vs MATLAB

siko1056
In reply to this post by hjborsje
On 3/11/20 12:42 AM, Henk Borsje wrote:
> I find that Octave can be 10 – 20 % slower than ML.  One significant
> exception I found to be the svd.  The default processing in Octave is
> rather slower than ML, especially when the matrix gets large.  There is
> a thread about this not that long ago.
>
> Henk Borsje
>


Did you read my answer in this thread [1]?  You can easily get the same
speed as Matlab, when you change the svd_driver [2] as Matlab does.
However this comes at the price of numerical stability, that Octave is
not willing to take by default, as Matlab does.

Kai

[1] https://lists.gnu.org/archive/html/help-octave/2020-01/msg00148.html
[2] https://octave.org/doc/v5.2.0/XREFsvd_005fdriver.html