<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Simplify function but code slows down instead of speed up in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748083#M5397</link>
    <description>&lt;P&gt;Thanks Steve!&lt;/P&gt;
&lt;P&gt;I just did a profiling using the new option -xP since I'm using c2d processor. There seems to be a slight increase for some routines although it's not really conclusive. &lt;/P&gt;
&lt;P&gt;I then did -ipo and there is a 20% increase! Moreover I found that the profiling output is now pretty different after using -ipo. I can't find the phi_f function anymore.&lt;/P&gt;
&lt;P&gt;Since we are at optimization, what's the difference between -ip and -ipo? Why is the profiling output so different?&lt;/P&gt;
&lt;P&gt;Another thing is after using -ipo, I found that using the original phi_f is even slightly faster than phi_f_new or phi_f_new2.&lt;/P&gt;
&lt;P&gt;Any idea why simplifying the function I mention earlier slows down the speed instead? I still don't understand.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 14 May 2008 05:10:33 GMT</pubDate>
    <dc:creator>Wee_Beng_T_</dc:creator>
    <dc:date>2008-05-14T05:10:33Z</dc:date>
    <item>
      <title>Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748079#M5393</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I did a profiling using the -p option. From the results, I found that about 22% of the time is spent executing a particularfunction phi_f() given by&lt;/P&gt;&lt;P&gt;real(8) function phi_f(u1,u2,d1,d2)&lt;/P&gt;&lt;P&gt;real(8), intent(in) :: u1,u2,d1,d2&lt;/P&gt;&lt;P&gt;phi_f = (d1*u2+d2*u1)/(d1+d2)&lt;/P&gt;&lt;P&gt;end function phi_f&lt;/P&gt;&lt;P&gt;For e.g. phi_f(u(i,j),u(i+1,j),cu(i,j)%pd_E,cu(i+1,j)%pd_W)&lt;/P&gt;&lt;P&gt;Since d1,d2 are constants at each time step and only u1 and u2 change, I decided to simplify the function by changing it to&lt;/P&gt;&lt;P&gt;real(8) function phi_f_new(u1,u2,d1,d2,inv_d)&lt;/P&gt;&lt;P&gt;real(8), intent(in) :: u1,u2,d1,d2,inv_d&lt;/P&gt;&lt;P&gt;phi_f_new = (d1*u2+d2*u1)*inv_d&lt;/P&gt;&lt;P&gt;end function phi_f_new&lt;/P&gt;&lt;P&gt;where inv_d=1./(d1+d2).&lt;/P&gt;&lt;P&gt;For e.g. phi_f_new(u(i,j),u(i+1,j),cu(i,j)%pd_E,cu(i+1,j)%pd_W,cu(i,j)%inv_d_PE)&lt;/P&gt;&lt;P&gt;and then to&lt;/P&gt;&lt;P&gt;real(8) function phi_f_new2(u1,u2,dd1,dd2)&lt;/P&gt;&lt;P&gt;real(8), intent(in) :: u1,u2,dd1,dd2&lt;/P&gt;&lt;P&gt;phi_f_new2 = dd1*u2+dd2*u1&lt;/P&gt;&lt;P&gt;end function phi_f_new2&lt;/P&gt;&lt;P&gt;dd1 and dd2 are acutally d1/(d1+d2) and d2/(d1+d2). They are computed initially and stored.&lt;/P&gt;&lt;P&gt;For e.g. phi_f_new2(u(i,j),u(i+1,j),cu(i,j)%ratio_Pe_PE,cu(i+1,j)%ratio_Pw_PW)&lt;/P&gt;&lt;P&gt;I thought that using the 2nd function (phi_f_new) will be faster than the 1st (phi_f) and the 3rd function (phi_f_new2) will be faster than the 2nd. However, after doing profiling again, I found that phi_f_new is faster than phi_f, but phi_f_new2 is slower than phi_f_new.&lt;/P&gt;&lt;P&gt;I thought the operation counts have reduced and it should be faster, shouldn't it?&lt;/P&gt;&lt;P&gt;It seems that the difference is smaller when I increase the no. of grid points, although it's still slower.&lt;/P&gt;</description>
      <pubDate>Tue, 13 May 2008 05:11:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748079#M5393</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2008-05-13T05:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748080#M5394</link>
      <description>I'll ask the obvious question: if this trivial function is 22% of your runtime, why not get it to inline with -ip or -ipo?&lt;BR /&gt;&lt;BR /&gt;I think tweaking the function will give some marginal improvement, but if you can inline it you may see a very very dramatic speedup for the application.&lt;BR /&gt;&lt;BR /&gt;ron&lt;BR /&gt;</description>
      <pubDate>Tue, 13 May 2008 14:48:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748080#M5394</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-05-13T14:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748081#M5395</link>
      <description>&lt;P&gt;Thank you for your suggestion Ron!&lt;/P&gt;
&lt;P&gt;However, I have already used -ip during compiling. Btw, my compiler options are:&lt;/P&gt;
&lt;P&gt;-p -O3 -ip -r8 -w95 -c -static-libcxa&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2008 00:21:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748081#M5395</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2008-05-14T00:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748082#M5396</link>
      <description>Tried the -x option appropriate for your processor?&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 01:13:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748082#M5396</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-05-14T01:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748083#M5397</link>
      <description>&lt;P&gt;Thanks Steve!&lt;/P&gt;
&lt;P&gt;I just did a profiling using the new option -xP since I'm using c2d processor. There seems to be a slight increase for some routines although it's not really conclusive. &lt;/P&gt;
&lt;P&gt;I then did -ipo and there is a 20% increase! Moreover I found that the profiling output is now pretty different after using -ipo. I can't find the phi_f function anymore.&lt;/P&gt;
&lt;P&gt;Since we are at optimization, what's the difference between -ip and -ipo? Why is the profiling output so different?&lt;/P&gt;
&lt;P&gt;Another thing is after using -ipo, I found that using the original phi_f is even slightly faster than phi_f_new or phi_f_new2.&lt;/P&gt;
&lt;P&gt;Any idea why simplifying the function I mention earlier slows down the speed instead? I still don't understand.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2008 05:10:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748083#M5397</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2008-05-14T05:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748084#M5398</link>
      <description>-ip does analysis within a single source file only, and in recent compilers, a "light" form of -ip is done by default, so you nmay not see much benefit from -ip.&lt;BR /&gt;&lt;BR /&gt;-ipo analyzes the entire application across all source files. It's as if you merged all the sources into one file and compiled that one file with -ip. -ipo provides much more information to the optimizer and allows it to make better inlining and vectorization decisions. I'd guess that with -ipo, phi_f is being completely inlined.&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 12:55:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748084#M5398</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-05-14T12:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748085#M5399</link>
      <description>Glad to see that the inlining helped. I was pretty sure it would.&lt;BR /&gt;&lt;BR /&gt;One last point on the code 'simplification': Modern compilers are quite clever at doing all the things you were attempting to do by hand to reduce the instruction count, convert division to reciprocal multiplication, etc. On top of that, advances in chip technology are also changing the rules: on the latest processors, the division can sometimes be almost as fast as a mult by a reciprocal approximation. In the future, who knows, might be as fast or faster.&lt;BR /&gt;&lt;BR /&gt;In addition, the compiler can and does do things with register allocations of variables, streaming stores, vectorizations, etc. Things that would take a clever programmer a LONG time to do. Recently on our Forums we had a customer that hand-coded assembly to try to outdo the compiler. It turned out the compiled code and his hand-tuned assembly were approximately equal. He was stunned, to say the least.&lt;BR /&gt;&lt;BR /&gt;Like a lot of Fortran programmers, we cut our teeth in a time when we didn't trust compilers and did a LOT of modifications to the code to outguess the compiler and tune the code to a particular architecture. I remember rewriting a lot of key routines in DEC assembler to get the extra boost I needed in my application performance. The downside is obvious: those inheriting my old codes have probably cursed me to no end.&lt;BR /&gt;&lt;BR /&gt;What I'm getting at: these days the best advice is to write your code in the most straightforward way, a way that reflects the algorithm. Modern compilers do a bang-up job on the optimization, often as good or better than you could do by hand. And even if you do some clever things today, a new chip advance may make your effort irrelevant. Also the code modifications often obscure the underlying algorithm and are counter to the goal of maintainable code.&lt;BR /&gt;&lt;BR /&gt;ron&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 14:01:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748085#M5399</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-05-14T14:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify function but code slows down instead of speed up</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748086#M5400</link>
      <description>Thank you for the enlightenment Steve and Ron! I now have a better understand of the compiler and their capabilities.</description>
      <pubDate>Wed, 14 May 2008 15:28:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Simplify-function-but-code-slows-down-instead-of-speed-up/m-p/748086#M5400</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2008-05-14T15:28:40Z</dc:date>
    </item>
  </channel>
</rss>

