topic Computational cost of evaluating Real VS Complex functions in IntelĀ® Fortran Compiler
https://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156915#M141823
<P>For a numerical application I'm doing, I have the choice to compute the functions in the Complex domain or in the Real domain (I will not go into details since it's not relevant). I was wondering what is the difference in computational cost of evaluating a function in each domain. For instance, consider the following two functions:</P>
<PRE class="brush:fortran; class-name:dark;">function f_cmlpx(x) result(y)
double complex, intent(in) :: x ! input
double complex :: y ! output
y = atan(x)/(1+exp(-x**2))
end function f_cmlpx
function f(x) result(y)
double precision, intent(in) :: x ! input
double precision :: y ! output
y = atan(x)/(1+exp(-x**2))
end function f</PRE>
<P>How much more expensive would be the complex evaluation than the real one?</P>Tue, 17 Jul 2018 12:25:05 GMTPetros_A_12018-07-17T12:25:05ZComputational cost of evaluating Real VS Complex functions
https://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156915#M141823
<P>For a numerical application I'm doing, I have the choice to compute the functions in the Complex domain or in the Real domain (I will not go into details since it's not relevant). I was wondering what is the difference in computational cost of evaluating a function in each domain. For instance, consider the following two functions:</P>
<PRE class="brush:fortran; class-name:dark;">function f_cmlpx(x) result(y)
double complex, intent(in) :: x ! input
double complex :: y ! output
y = atan(x)/(1+exp(-x**2))
end function f_cmlpx
function f(x) result(y)
double precision, intent(in) :: x ! input
double precision :: y ! output
y = atan(x)/(1+exp(-x**2))
end function f</PRE>
<P>How much more expensive would be the complex evaluation than the real one?</P>Tue, 17 Jul 2018 12:25:05 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156915#M141823Petros_A_12018-07-17T12:25:05ZBasic mathematics will tell
https://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156916#M141824
<P>Basic mathematics will tell you that any complex operation will require two to four times as much work as a real operation. There's also twice as much data in a complex value, which incurs memory and data transfer costs. None of that comes for free.</P>Tue, 17 Jul 2018 13:23:40 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156916#M141824Steve_Lionel2018-07-17T13:23:40ZQuote:Steve Lionel (Ret.)
https://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156917#M141825
<P></P><BLOCKQUOTE>Steve Lionel (Ret.) wrote:<BR /><P></P>
<P>Basic mathematics will tell you that any complex operation will require two to four times as much work as a real operation. There's also twice as much data in a complex value, which incurs memory and data transfer costs. None of that comes for free.</P>
<P></P></BLOCKQUOTE><P></P>
<P>Hi Steve, thanks for the input. Sometimes, unfortunately, it is not that obvious. For instance, to multiply two nXn complex matrices requires 8n^3 complex scalar multiplications if the obvious way. But if you use a formula for multiplying two complex scalars in 3 real multiplications the cost can be reduced to 6n^3 flops [1].</P>
<P>So, my question was more to the sense, are there any optimisations performed behind the scenes or is it done in the "basic mathematics" way?</P>
<P>Thanks again.</P>
<P>[1] Higham, N.J.: Accuracy and Stability of Numerical Algorithms. Second edn. Society for Industrial and Applied Mathematics, Philadelphia, PA, USA (2002)</P>
<P> </P>Tue, 17 Jul 2018 17:27:42 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156917#M141825Petros_A_12018-07-17T17:27:42ZI have never found it helpful
https://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156918#M141826
<P>I have never found it helpful to generate an algorithm or to code based on what I think the compiler might be doing under full optimization. It has always proved necessary to generate reasonable tests, do some timings, and use VTune to see what is computationally expensive. But some things can be anticipated . . . in the code sample you provided, it surely must be the case that asking for a complex arctan and exponentiation is considerably more expensive than the simple real equivalent. But I have found that only testing with code compiled under full optimization shows whether the difference in execution time is actually important. </P>
<P>The SIAM book you reference does contain some very helpful algorithms, but (again) I have found surprises in actual code performance. The 25% reduction in flops you pointed out could be completely swamped by memory access times, cache flushing, poor array layout, and other problems. Threading adds another level of uncertainty to this problem.</P>Tue, 17 Jul 2018 17:55:08 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Computational-cost-of-evaluating-Real-VS-Complex-functions/m-p/1156918#M141826David_DiLaura12018-07-17T17:55:08Z