bugGNU Octave - Bugs: bug #49667, Computing integer powers of...

 
 

bug #49667: Computing integer powers of complex numbers in 4.2.0 is slower than in 4.0.3 with GCC 4.8

Submitter:  Marco Caliari <caliari>
Submitted:  Tue 22 Nov 2016 09:13:13 AM UTC
   
 
Category:  Performance Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Performance
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 23 Nov 2016 06:12:01 PM UTC, comment #7: 

The PPA is a backport of whatever is in the development release. So once 4.2.0 appears in the "zesty" release or whatever comes after, then I will backport it into the PPA. And it probably will have this problem, unless there is an easy way to pull in a newer gcc.

Mike Miller <mtmiller>
Group Member
Wed 23 Nov 2016 07:59:13 AM UTC, comment #6: 

Mike, I agree with your analysis. Are you going to make a PPA version for Ubuntu 14.04? In that case, will it have the same problem?

Marco Caliari <caliari>
Group Member
Tue 22 Nov 2016 08:22:04 PM UTC, comment #5: 

Correct, I believe it is because the std::pow(std::complex<T>, int) overload was conditionally compiled out of existence in earlier versions of gcc when using the -std=gnu++11 or -std=gnu++0x command-line option, but was available when building in (previously the default) C++98 mode.

With gcc 5, the specialization was reinstated when building in C++11 mode, and the performance is as it was.

I think a user on Ubuntu 14.04 or Mint 17 could confirm this by using gdb or perf and showing that the inline function std::__complex_pow_unsigned is not being called at all. But I've looked at this for about a half hour now and I'm pretty convinced by inspection that this is the case.

Mike Miller <mtmiller>
Group Member
Tue 22 Nov 2016 08:05:52 PM UTC, comment #4: 

So the problem only appears if using an older GCC?  In that case, I don't think there is anything we should do about this problem in Octave.

John W. Eaton <jwe>
Group administrator
Tue 22 Nov 2016 07:51:32 PM UTC, comment #3: 

Avinoam - I think it's pretty clear this is related to the older toolchain on Ubuntu 14.04 / Mint 17, but thanks for confirming anyway.

Related: http://stackoverflow.com/q/5627030/384593, bug #38142

Compare the definition of std::pow(std::complex<double>, int) in gcc 4.8.4 (the version in Ubuntu 14.04)

https://github.com/gcc-mirror/gcc/blob/gcc-4_8_4-release/libstdc%2B%2B-v3/include/std/complex#L975

with the same function in gcc 5 / 6

https://github.com/gcc-mirror/gcc/blob/gcc-5_1_0-release/libstdc%2B%2B-v3/include/std/complex#L976

So yes, I would say that this performance degradation is a defect in gcc 4.8 running in C++11 mode.

Mike Miller <mtmiller>
Group Member
Tue 22 Nov 2016 07:29:44 PM UTC, comment #2: 

Checking on Win-10 32 bit:

4.0.3:


>>  z=rand(1000)+1i*rand(1000);
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.029856 seconds.
Elapsed time is 0.0566921 seconds.
Elapsed time is 0.470668 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.019012 seconds.
Elapsed time is 0.046031 seconds.
Elapsed time is 0.454301 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.0210109 seconds.
Elapsed time is 0.04603 seconds.
Elapsed time is 0.449299 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.02001 seconds.
Elapsed time is 0.046031 seconds.
Elapsed time is 0.450298 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.02001 seconds.
Elapsed time is 0.0450299 seconds.
Elapsed time is 0.450299 seconds.


4.2.0:


>>  z=rand(1000)+1i*rand(1000);
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.018013 seconds.
Elapsed time is 0.040025 seconds.
Elapsed time is 0.42469 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.0192781 seconds.
Elapsed time is 0.040027 seconds.
Elapsed time is 0.423281 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.019012 seconds.
Elapsed time is 0.040027 seconds.
Elapsed time is 0.423281 seconds.
>> tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.0184521 seconds.
Elapsed time is 0.0410269 seconds.
Elapsed time is 0.42228 seconds.


There is no noticeable difference.

Avinoam Kalma <avinoam>
Group Member
Tue 22 Nov 2016 07:11:40 PM UTC, comment #1: 

If it's only a problem on Ubuntu 14.04 / Mint 17, then it looks like you are arguing that it's not an Octave bug. It's very possible that some of the C++11 math functions that we started using in 4.2 have some problems with an older toolchain of gcc/libc/libm/libstdc++. Maybe using perf or valgrind --tool=callgrind can help shed some light on what underlying library calls are different for you between 4.0 and 4.2. That might help demonstrate that it is the system libraries to blame for the performance difference, not necessarily that we may do anything about this in Octave.

For what it's worth, on Debian with gcc 6 and glibc 2.24, I get just about identical performance between 3.6.4 and 4.2.0.

Mike Miller <mtmiller>
Group Member
Tue 22 Nov 2016 09:13:13 AM UTC, original submission:  

Dear all,

I compiled from scratch 4.0.3 and 4.2.0 and observe the following


GNU Octave, version 4.2.0
>> z=rand(1000)+1i*rand(1000);
tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.0171239 seconds.
Elapsed time is 0.247205 seconds.
Elapsed time is 0.243459 seconds.

GNU Octave, version 4.0.3
>> z=rand(1000)+1i*rand(1000);
tic,z.*z;,toc,tic,z.^2;,toc,tic,exp(2*log(z));,toc
Elapsed time is 0.00733209 seconds.
Elapsed time is 0.017849 seconds.
Elapsed time is 0.245989 seconds.


So, it seems that integer powers of complex numbers are now treated as double powers. I'm on Mint 17.3 (Ubuntu 14.04). A user in chat showed me that 4.2.0 behaves like 4.0.3 on Ubuntu 16.04. So, it is an Ubuntu 14.04 related problem.

Marco Caliari <caliari>
Group Member

 

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

Attach Files:
   
   
Comment:
   

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 jwe (Posted a comment)
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by caliari (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-22 mtmiller Open/ClosedOpen Closed
        SummaryComputing powers of complex numbers in 4.2.0 is slower than in 4.0.3 Computing integer powers of complex numbers in 4.2.0 is slower than in 4.0.3 with GCC 4.8
    2016-11-22 mtmiller StatusNeed Info Wont Fix
    2016-11-22 mtmiller Item GroupRegression Performance
        StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code