<?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: Fortran 90 Optimisation in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836167#M55152</link>
    <description>This is not my area of expertise, but a routine to be inlined needs to have certain properties - generally those that allow the compiler to, in a figurative sense, treat the routine call as a "macro expansion".  If you pass variables that are manipulated in the routine, the compiler can do those same manipulations in inline code.  A function that returns a scalar result is pretty much a drop-in replacement, too.  But your routine constructs a temporary array on the stack, which the compilers can't just replace with code.  Yes, I suppose with more extensive analysis to see what you're doing with the array, something may be possible, but the Fortran semantics of your function call are subtly different from the subroutine or your own inline expansion.&lt;BR /&gt;&lt;BR /&gt;Inlining is not a magic wand - not everything is inlineable.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
    <pubDate>Sun, 24 Nov 2002 09:53:54 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2002-11-24T09:53:54Z</dc:date>
    <item>
      <title>Fortran 90 Optimisation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836164#M55149</link>
      <description>I have written a Fortran 90 module to perform a vector cross product with a variety of data types.  These routines are called many thousands of times in my software and therefore I would like them to be inlined.  However, I am unable to find an compiler option to inline the functions.&lt;BR /&gt;&lt;BR /&gt;I have generated a cut down test case :-&lt;BR /&gt;&lt;BR /&gt;module module_vec3d&lt;BR /&gt;&lt;BR /&gt;    interface cross_product&lt;BR /&gt;        module procedure cross_product_R4_R4&lt;BR /&gt;    end interface&lt;BR /&gt;&lt;BR /&gt;contains&lt;BR /&gt;&lt;BR /&gt;    function cross_product_R4_R4(x, y) result(z)&lt;BR /&gt;&lt;BR /&gt;        real :: z(3)&lt;BR /&gt;        real, intent(in) :: x(3), y(3)&lt;BR /&gt;&lt;BR /&gt;        z = (/ x(2) * y(3) - x(3) * y(2), &amp;amp;&lt;BR /&gt;               x(3) * y(1) - x(1) * y(3), &amp;amp;&lt;BR /&gt;               x(1) * y(2) - x(2) * y(1) /)&lt;BR /&gt;        return&lt;BR /&gt;    end function cross_product_R4_R4&lt;BR /&gt;&lt;BR /&gt;end module module_vec3d&lt;BR /&gt;&lt;BR /&gt;program try_dp&lt;BR /&gt;&lt;BR /&gt;#ifndef INLINE&lt;BR /&gt;    use module_vec3d&lt;BR /&gt;#endif&lt;BR /&gt;&lt;BR /&gt;    integer, parameter :: N = 10000&lt;BR /&gt;    real :: a(3, N), c(3, N)&lt;BR /&gt;    real :: time_begin, time_end&lt;BR /&gt;    integer :: i, j&lt;BR /&gt;&lt;BR /&gt;    do i = 1, N&lt;BR /&gt;        a(:, i) = (/ 0.1 + 0.05 * i / N, 0.2 - 0.1 * i / N, 0.3 - 0.05 * i / N /)&lt;BR /&gt;    enddo&lt;BR /&gt;    c(:,:) = 0.0&lt;BR /&gt;&lt;BR /&gt;    call cpu_time(time_begin)&lt;BR /&gt;    do j = 1, N&lt;BR /&gt;        do i = 1, N&lt;BR /&gt;#ifdef INLINE&lt;BR /&gt;            c(1, j) = c(1, j) + a(2, i) * a(3, j) - a(3, i) * a(2, j)&lt;BR /&gt;            c(2, j) = c(2, j) + a(3, i) * a(1, j) - a(1, i) * a(3, j)&lt;BR /&gt;            c(3, j) = c(3, j) + a(1, i) * a(2, j) - a(2, i) * a(1, j)&lt;BR /&gt;#else&lt;BR /&gt;            c(:, j) = c(:, j) + cross_product(a(:, i), a(:, j))&lt;BR /&gt;#endif&lt;BR /&gt;        enddo&lt;BR /&gt;    enddo&lt;BR /&gt;    call cpu_time(time_end)&lt;BR /&gt;    print *, time_end - time_begin&lt;BR /&gt;&lt;BR /&gt;    write(20,*) c&lt;BR /&gt;&lt;BR /&gt;end program try_dp&lt;BR /&gt;&lt;BR /&gt;Using the manual inline code (#ifdef INLINE), the run time is reduced by a factor of 3 on my machine.  How can I force the compiler to inline these functions?&lt;BR /&gt;&lt;BR /&gt;P.S. I have downloaded a trial version of Intel Fortran v7 and the performance for the module function is even worse.</description>
      <pubDate>Fri, 22 Nov 2002 23:05:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836164#M55149</guid>
      <dc:creator>john_lord</dc:creator>
      <dc:date>2002-11-22T23:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran 90 Optimisation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836165#M55150</link>
      <description>With CVF, you can use the /inline:all option - there is not a way to specify inlining of a specific routine.  Note that in CVF, the inlined routine has to be in the same source file as the caller.  Even with :all, your routine may not be able to be inlined.&lt;BR /&gt;&lt;BR /&gt;However, it is not clear to me that the compiler can inline a function reference with array section arguments.  Is there some reason why you don't just have the whole loop version as a callable routine?  Compilers would be much happier with that.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Sat, 23 Nov 2002 00:00:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836165#M55150</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2002-11-23T00:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran 90 Optimisation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836166#M55151</link>
      <description>Steve,&lt;BR /&gt;&lt;BR /&gt;Thank you for your suggestions.&lt;BR /&gt;&lt;BR /&gt;I have found that if the module function is converted to a subroutine and the result is returned in the 3rd argument then the subroutine is inlined by the compiler (using /inline:all).  This is moderately inconvenient, since temporary variables are required and it affects the readability when the cross-product is used in long expressions.  Why will the compiler not inline a function that returns an array?</description>
      <pubDate>Sun, 24 Nov 2002 06:23:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836166#M55151</guid>
      <dc:creator>john_lord</dc:creator>
      <dc:date>2002-11-24T06:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Fortran 90 Optimisation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836167#M55152</link>
      <description>This is not my area of expertise, but a routine to be inlined needs to have certain properties - generally those that allow the compiler to, in a figurative sense, treat the routine call as a "macro expansion".  If you pass variables that are manipulated in the routine, the compiler can do those same manipulations in inline code.  A function that returns a scalar result is pretty much a drop-in replacement, too.  But your routine constructs a temporary array on the stack, which the compilers can't just replace with code.  Yes, I suppose with more extensive analysis to see what you're doing with the array, something may be possible, but the Fortran semantics of your function call are subtly different from the subroutine or your own inline expansion.&lt;BR /&gt;&lt;BR /&gt;Inlining is not a magic wand - not everything is inlineable.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Sun, 24 Nov 2002 09:53:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-90-Optimisation/m-p/836167#M55152</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2002-11-24T09:53:54Z</dc:date>
    </item>
  </channel>
</rss>

