<?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: Implicit shaped declarations in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339729#M158506</link>
    <description>&lt;P&gt;Yes, I want to try it that way. I develop numerical methods and publish articles in journals. Consequently, the computational performance of the computation is critical. Using implicit setting of array bounds is very convenient and allows you to reduce the number of errors in a program. However, if it excludes the possibility of optimization, this case will be unacceptable for numerical methods.&lt;/P&gt;</description>
    <pubDate>Sun, 28 Nov 2021 15:49:59 GMT</pubDate>
    <dc:creator>Andrew_</dc:creator>
    <dc:date>2021-11-28T15:49:59Z</dc:date>
    <item>
      <title>Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339697#M158501</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I have a question. The optimization manual&lt;/P&gt;
&lt;P&gt;(&lt;A href="https://www.umr-cnrm.fr/gmapdoc/IMG/pdf/general_fortran_optimization_guide_manual.pdf" target="_blank"&gt;https://www.umr-cnrm.fr/gmapdoc/IMG/pdf/general_fortran_optimization_guide_manual.pdf&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;says the following (page 8):&lt;/P&gt;
&lt;P&gt;Let us now reconsider the same kind of loop where the arrays are dummy arguments :&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;REAL, INTENT(OUT) :: A(N)&lt;BR /&gt;REAL, INTENT(IN) :: B(N)&lt;BR /&gt;REAL, INTENT(IN) :: C(N)&lt;BR /&gt;DO J=1,N&lt;BR /&gt;A(J)=B(J)*C(J)&lt;BR /&gt;ENDDO&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;That loop has a good spacial locality because the explicit dimensionning of the dummy arrays instructs the compiler that the data in each array are contiguous in memory.&lt;BR /&gt;However the Fortran language offer the possibility to write the same code with implicit declarations, which can make the code more robust against bugs :&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;REAL, INTENT(OUT) :: A(:)&lt;BR /&gt;REAL, INTENT(IN) :: B(:)&lt;BR /&gt;REAL, INTENT(IN) :: C(:)&lt;BR /&gt;A(:)=B(:)*C(:)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Unfortunately that implicit shaped declarations also instruct the compiler that these dummy arrays are not necessarily contiguous in memory. The spacial locality of data being unknown to the compiler optimizer, it may prefer to disable any data prefetching rather to risk cache misses. &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Consequently that loop will run slower than the former one.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;!!!!!Therefore, Implicit shaped declarations should not be used!!!!!!&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;Can you tell me if that last recommendation is correct?&lt;/P&gt;
&lt;P&gt;I assumed that the performance for the both examples would be the same.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Nov 2021 08:23:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339697#M158501</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2021-11-28T08:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339713#M158503</link>
      <description>Any coding where decisions have to be made at run time rather than compile time might involve a little more work runtime. That said in this case I would not worry as any good compiler will optimise both and they get better all the time. Focus first on robust code IMO.</description>
      <pubDate>Sun, 28 Nov 2021 10:24:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339713#M158503</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2021-11-28T10:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339722#M158504</link>
      <description>&lt;P&gt;&lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/191810"&gt;@Andrew_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Firstly, I suggest you check the compiled object code generated by the compiler and evaluate it for performance.&amp;nbsp; In addition to Intel tools, you may also find Godbolt useful in case you have not used it:&amp;nbsp;&lt;A href="https://godbolt.org/" target="_blank"&gt;https://godbolt.org/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then I suggest you consider the &lt;STRONG&gt;&lt;A href="https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/language-reference/a-to-z-reference/c-to-d/contiguous.html" target="_self"&gt;CONTIGUOUS&lt;/A&gt; &lt;/STRONG&gt;attribute in the language and whether the compiler is able to take advantage of it:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;      real, contiguous, intent(out) :: a(:)
      real, contiguous, intent(in)  :: b(:)
      real, contiguous, intent(in)  :: c(:)
      a = b*c
&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 28 Nov 2021 14:02:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339722#M158504</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2021-11-28T14:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339728#M158505</link>
      <description>&lt;P&gt;I will further add that the implicit array will have an array descriptor . The format and contents of that descriptor are compiler (processor) dependant. However,&amp;nbsp; the descriptor&amp;nbsp; will have all sorts of useful info like the strides of the&amp;nbsp; dimensions&amp;nbsp; and in the case of intel there is a flag for contiguous or not. The author in saying don't use A = B*C because the compiler might be dumb in some instances.&amp;nbsp; This might be true of some compilers at some point in history but things change continuously. I am not convinced about spending my time unrolling implied loops manually, I will leave that to the compiler to decide and if my code is slow I will focus only on the hot spots from profilers.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Nov 2021 15:40:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339728#M158505</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2021-11-28T15:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339729#M158506</link>
      <description>&lt;P&gt;Yes, I want to try it that way. I develop numerical methods and publish articles in journals. Consequently, the computational performance of the computation is critical. Using implicit setting of array bounds is very convenient and allows you to reduce the number of errors in a program. However, if it excludes the possibility of optimization, this case will be unacceptable for numerical methods.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Nov 2021 15:49:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339729#M158506</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2021-11-28T15:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339838#M158511</link>
      <description>&lt;P&gt;Even if assumed-shape declarations cause slower code than explicit shapes (do you have actual measurements of that?), then you can still use them, as, like you say, they tend to make the interface simpler and less error-prone:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;subroutine do_something( array )
    real, dimension(:) :: array
    call do_something_private( array, size(array) )
    ...
end subroutine do_something
subroutine do_something_private( array, n )
    real, dimension(n) :: array
    ...
end subroutine do_something_private&lt;/LI-CODE&gt;
&lt;P&gt;By only exposing the simplified interface and doing the actual work in a private routine, you ought to get the best of both worlds. Of course there will be a slight overhead for the extra call, but if that is of concern, the workload will be very small indeed.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 07:22:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339838#M158511</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2021-11-29T07:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339861#M158514</link>
      <description>&lt;P&gt;The question is as follows. If the array to be passed is not continuous in memory, what will the compiler do? Create a continuous temporary copy of the array? If the compiler will create a continuous temporary copy of the array, that's fine. In this case, you can assume that a continuous array is always passed inside the procedure, and the compiler can perform code optimization as efficiently as possible.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 09:45:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339861#M158514</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2021-11-29T09:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339863#M158515</link>
      <description>&lt;P&gt;Yes, this is an interesting way to overcome the problem. But it doesn't look good, because debugging numerical procedures is very difficult. Also, programs usually include mpi, openmp, and such code redundancy is a nightmare. If I had one procedure, I would use the above method, but there are dozens of such procedures, and this approach adds bugs.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 09:51:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339863#M158515</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2021-11-29T09:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339864#M158516</link>
      <description>&lt;P&gt;I think one can try to pass an array X(1:N:2) to the subroutine.&lt;/P&gt;
&lt;P&gt;Then use run-time environment to see if a temporary array will be created.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 09:55:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339864#M158516</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2021-11-29T09:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339869#M158518</link>
      <description>&lt;P&gt;Normally creating temporary copies has a large overhead cost ( allocate some memory and copy to and from) so is often not fine. If there is no explicit interface and you are doing Fortran 77 style array passing then&amp;nbsp; you are in big big trouble if it is not continuous. memory so I don't thing that is a reasonable comparison to make.&amp;nbsp; &amp;nbsp;If you are using POD (plain old data types) and not passing none-contiguous slices&amp;nbsp; I would trust the compiler to make sensible decisions and not constrain the code based on presumptions of compiler behaviour.&amp;nbsp; If hot spot analysis show some bottlenecks then focus on understanding those.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 10:13:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339869#M158518</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2021-11-29T10:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339870#M158519</link>
      <description>&lt;P&gt;Look at the optimisation reports.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 10:15:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1339870#M158519</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2021-11-29T10:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Implicit shaped declarations</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1340167#M158544</link>
      <description>&lt;P&gt;I found the answer.&lt;/P&gt;
&lt;P&gt;There are two cases.&lt;/P&gt;
&lt;P&gt;CASE 1----------------------------------&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;subroutine do_something( array ) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;real, dimension(:),&lt;FONT face="arial black,avant garde" color="#FF0000"&gt;contiguous &lt;/FONT&gt;:: array&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;print *,is_contiguous(array)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end subroutine do_something&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CASE 2----------------------------------&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;subroutine do_something( array ) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;real, dimension(:) , contiguous :: array&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;print *,is_contiguous(array)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end subroutine do_something&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the first case, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the array will always be continuous. However, if the Array parameter is non-contiguous, a temporary array will be created.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the second case, a temporary array is never created when a parameter is passed. However, &lt;BR /&gt;print *,is_contiguous(array) will be FALSE.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 08:09:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-shaped-declarations/m-p/1340167#M158544</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2021-11-30T08:09:05Z</dc:date>
    </item>
  </channel>
</rss>

