<?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 If the array has the same in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038650#M112406</link>
    <description>&lt;P&gt;If the array has the same shape, it is not reallocated. I don't know of a foolproof way to detect reallocation. You could take the address of the LHS before and after and see if they're the same. If they're not, reallocation occurred. If they are, then reallocation probably didn't occur but if the same size got reallocated it might have the same address.&lt;/P&gt;

&lt;P&gt;Be aware, though, that you can't change the rank of an array through intrinsic assignment. You seem to be assuming that this can be done.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Oct 2014 15:34:13 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2014-10-28T15:34:13Z</dc:date>
    <item>
      <title>Check if allocatable array on the LHS is reallocated?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038649#M112405</link>
      <description>&lt;P&gt;I have recently stumbled over the handling of standard semantics in ifort, specifally how allocatable arrays are dealt with. In particular, the following description of realloc_lhs in ifort's manpage raised some questions:&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;assume realloc_lhs
                                Tells  the compiler that when the left-hand side of an assignment is an allocatable object,
                                it should be reallocated to the shape of the right-hand side of the assignment before the
                                assignment occurs. This is the Fortran 2003 definition. This feature may cause extra
                                overhead at run time.&lt;/PRE&gt;

&lt;P&gt;Now my questions is: what happens if the LHS is &lt;STRONG&gt;already allocated and has the same shame&lt;/STRONG&gt; as the RHS? Will it be reallocated anyways? Is there a way to check this? See the following MWE:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program mytest
    implicit none

    integer, dimension(:), allocatable :: a1, a2
    integer :: arrsize
    integer :: i

    arrsize = 10

    allocate(a1(arrsize))
    allocate(a2(arrsize))

    a2 = [ (i=1, arrsize) ]

    ! Is a1 reallocated here?
    a1 = a2

    ! This ensures non-reallocation, but fixes the arrays' ranks
    a1(:) = a2(:)

end program mytest
&lt;/PRE&gt;

&lt;P&gt;In principle I could of course use the second way of assining a2 to a1. However, I'd prefer using “a1 = a2”, since that notation allows for arbitrary rank arrays, while the second option fixes my arrays' ranks.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 14:50:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038649#M112405</guid>
      <dc:creator>mSSM_B_</dc:creator>
      <dc:date>2014-10-28T14:50:10Z</dc:date>
    </item>
    <item>
      <title>If the array has the same</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038650#M112406</link>
      <description>&lt;P&gt;If the array has the same shape, it is not reallocated. I don't know of a foolproof way to detect reallocation. You could take the address of the LHS before and after and see if they're the same. If they're not, reallocation occurred. If they are, then reallocation probably didn't occur but if the same size got reallocated it might have the same address.&lt;/P&gt;

&lt;P&gt;Be aware, though, that you can't change the rank of an array through intrinsic assignment. You seem to be assuming that this can be done.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 15:34:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038650#M112406</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-10-28T15:34:13Z</dc:date>
    </item>
    <item>
      <title>Thanks for the clarification.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038651#M112407</link>
      <description>&lt;P&gt;Thanks for the clarification. I should indeed have a look at the memory addresses (I guess there is a chance that the address before and after a potential reallocation might coincide, but I suppose the odds are negligible).&lt;/P&gt;

&lt;P&gt;Thank you also for the comment on the array ranks. I just noticed that my MWE doesn't exactly reflect my use case. My arrays are actually defined and allocated in a module, and then use-d by my subroutines. Their ranks and shapes match up by definition, s.t. the above example would look rather like below (making it more obvious why I am interested in not fixing ranks):&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;subroutine my_modifying_routine

    use my_array_module, only: a1, a2

    a1 = a2

end my_modifying_routine
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 16:19:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038651#M112407</guid>
      <dc:creator>mSSM_B_</dc:creator>
      <dc:date>2014-10-28T16:19:51Z</dc:date>
    </item>
    <item>
      <title>I would just use the regular</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038652#M112408</link>
      <description>&lt;P&gt;I would just use the regular assignment and not worry about it - with -standard-semantics enabled.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 16:33:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038652#M112408</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-10-28T16:33:09Z</dc:date>
    </item>
    <item>
      <title>Only the ‘(:)’ on the LHS of</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038653#M112409</link>
      <description>&lt;P&gt;Only the ‘(:)’ on the LHS of assignment is needed to prevent reallocation, FYI, if you want to guarantee no reallocation, and as you noted, you must be careful about the rank when using it.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 20:57:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038653#M112409</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2014-10-28T20:57:17Z</dc:date>
    </item>
    <item>
      <title>Well, no, you don't have to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038654#M112410</link>
      <description>&lt;P&gt;Well, no, you don't have to be careful about the rank, as the compiler will let you know if those don't match. You DO have to be careful about the shape.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Oct 2014 21:35:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038654#M112410</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-10-28T21:35:22Z</dc:date>
    </item>
    <item>
      <title>Yes, I just mean, make sure</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038655#M112411</link>
      <description>&lt;P&gt;Yes, I just mean, make sure you have the correct number of colons… but as you point out, the compiler will alert you at compile time.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 01:37:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038655#M112411</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2014-10-29T01:37:05Z</dc:date>
    </item>
    <item>
      <title>Quote:Steve Lionel (Intel)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038656#M112412</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Steve Lionel (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;If the array has the same shape, it is not reallocated. I don't know of a foolproof way to detect reallocation. You could take the address of the LHS before and after and see if they're the same. If they're not, reallocation occurred. If they are, then reallocation probably didn't occur but if the same size got reallocated it might have the same address.&lt;/P&gt;

&lt;P&gt;Be aware, though, that you can't change the rank of an array through intrinsic assignment. You seem to be assuming that this can be done.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Steve,&lt;/P&gt;

&lt;P&gt;Is it possible to add a run-time debugging option, similar to -check:arg_temp_created (call it say -check:reallocation), that can allow users to test for this while debugging their code? &amp;nbsp;If Intel team can come up with some option along such lines for such checking, it will be really useful. &amp;nbsp;So basically I'm suggesting if the run-time environment along with ifort can do what you suggested, "&lt;SPAN style="line-height: 19.5120010375977px;"&gt;take the address of the LHS before and after and see if they're the same. If they're not, reallocation occurred&lt;/SPAN&gt;", and alert the user accordingly.&lt;/P&gt;

&lt;P&gt;Food for thought,&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 14:05:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038656#M112412</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-10-29T14:05:00Z</dc:date>
    </item>
    <item>
      <title>We are generally reluctant to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038657#M112413</link>
      <description>&lt;P&gt;We are generally reluctant to add diagnostics for features that are integral to the language, especially as in this case you're going to get correct results. What would be the purpose in such an option? There are many applications that depend on the now-standard behavior - so many so nowadays that we are considering making -assume realloc_lhs the default in a future release, the way some other compilers have recently done.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 14:17:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038657#M112413</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-10-29T14:17:58Z</dc:date>
    </item>
    <item>
      <title>Quote:FortranFan wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038658#M112414</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;FortranFan wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG class="quote-header"&gt;Quote:&lt;/STRONG&gt;&lt;/P&gt;

&lt;BLOCKQUOTE class="quote-msg quote-nest-1 odd"&gt;
	&lt;DIV class="quote-author"&gt;&lt;EM class="placeholder"&gt;Steve Lionel (Intel)&lt;/EM&gt; wrote:&lt;/DIV&gt;

	&lt;P&gt;&amp;nbsp;&lt;/P&gt;

	&lt;P&gt;If the array has the same shape, it is not reallocated. I don't know of a foolproof way to detect reallocation. You could take the address of the LHS before and after and see if they're the same. If they're not, reallocation occurred. If they are, then reallocation probably didn't occur but if the same size got reallocated it might have the same address.&lt;/P&gt;

	&lt;P&gt;Be aware, though, that you can't change the rank of an array through intrinsic assignment. You seem to be assuming that this can be done.&lt;/P&gt;

	&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Steve,&lt;/P&gt;

&lt;P&gt;Is it possible to add a run-time debugging option, similar to -check:arg_temp_created (call it say -check:reallocation), that can allow users to test for this while debugging their code? &amp;nbsp;If Intel team can come up with some option along such lines for such checking, it will be really useful. &amp;nbsp;So basically I'm suggesting if the run-time environment along with ifort can do what you suggested, "take the address of the LHS before and after and see if they're the same. If they're not, reallocation occurred", and alert the user accordingly.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;What's the use case?&lt;/P&gt;

&lt;P&gt;For non-polymorphic objects with no deferred length parameters you can do it yourself with `IF (ANY(SHAPE(lhs) /= SHAPE(rhs))) PRINT "('Reallocation!')"` or similar.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Runtime diagnostics for shape mismatches in assignments where the left hand side isn't allocatable strikes me as far more useful.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 14:24:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038658#M112414</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2014-10-29T14:24:34Z</dc:date>
    </item>
    <item>
      <title>Quote:Steve Lionel (Intel)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038659#M112415</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Steve Lionel (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;We are generally reluctant to add diagnostics for features that are integral to the language, especially as in this case you're going to get correct results. What would be the purpose in such an option? There are many applications that depend on the now-standard behavior - so many so nowadays that we are considering making -assume realloc_lhs the default in a future release, the way some other compilers have recently done.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Steve,&lt;/P&gt;

&lt;P&gt;Can you please explain the value of -&lt;SPAN style="color: rgb(51, 51, 51); font-family: 'Courier New', Courier, monospace; line-height: 16px;"&gt;check arg_temp_created&lt;/SPAN&gt;? &amp;nbsp;Is there any value to it beyond being "informative" when temporary storage is created before procedure calls. &amp;nbsp;Does this feature have &lt;SPAN style="line-height: 19.5120010375977px;"&gt;relevance to any wrong/right results? &amp;nbsp;The way we use it, it simply allows us to focus our attention on situations where temporary storage is involved during procedure invocations. &amp;nbsp;So if the temporary storage is not intentional (an aspect some other coder might have overlooked during development), the team can investigate code redesign to avoid it. &amp;nbsp;Quite handy, since it is part of ifort.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Now when working with arrays, we do see situations where unintentional and costly reallocations are taking place in compute-intensive code (e.g., in an utility used by a solver that is invoked frequently in some simulation) because of coder oversight (yes, the allocatable attribute does get abused at times). &amp;nbsp;Perhaps VTune Amplifier can point out situations, but it is a separate tool often out of reach. &amp;nbsp;Hence&amp;nbsp;&lt;SPAN style="line-height: 19.5120010375977px;"&gt;I was thinking a built-in check in ifort will be handy.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 20:30:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038659#M112415</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-10-30T20:30:30Z</dc:date>
    </item>
    <item>
      <title>Quote:IanH wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038660#M112416</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;IanH wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG class="quote-header"&gt;Quote:&lt;/STRONG&gt;&lt;/P&gt;

&lt;BLOCKQUOTE class="quote-msg quote-nest-1 odd"&gt;
	&lt;DIV class="quote-author"&gt;&lt;EM class="placeholder"&gt;FortranFan&lt;/EM&gt; wrote:&lt;/DIV&gt;

	&lt;P&gt;&amp;nbsp;&lt;/P&gt;

	&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Steve,&lt;/SPAN&gt;&lt;/P&gt;

	&lt;P&gt;Is it possible to add a run-time debugging option, similar to -check:arg_temp_created (call it say -check:reallocation), that can allow users to test for this while debugging their code? &amp;nbsp;...&lt;/P&gt;

	&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;What's the use case?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;For non-polymorphic objects with no deferred length parameters you can do it yourself with `IF (ANY(SHAPE(lhs) /= SHAPE(rhs))) PRINT "('Reallocation!')"` or similar.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;..&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;The use case is quick and easy diagnostics of unintentional reallocations in assignments. &amp;nbsp;We did have a situation where a utility in a solver was chewing up more compute time than necessary due to reallocations of some of the work areas as the problem space considered by the solver was changing. &amp;nbsp;The overall team would sooner or later catch such scenarios during performance evaluation of the simulator, but it could be sooner if ifort had a handy option to alert the user. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 20:44:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038660#M112416</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-10-30T20:44:16Z</dc:date>
    </item>
    <item>
      <title>-check arg_temp_created</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038661#M112417</link>
      <description>&lt;P&gt;-check arg_temp_created applies to argument passing where the compiler has to do copy-in/copy-out because of a mismatch in assumptions, generally related to noncontiguous arrays being passed to contiguous arrays. The copying can be a serious performance issue.&lt;/P&gt;

&lt;P&gt;In the assignment case, you're already doing a copy - the issue is merely one of reallocation which isn't all that expensive and tends to be constant time.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 20:56:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-allocatable-array-on-the-LHS-is-reallocated/m-p/1038661#M112417</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2014-10-30T20:56:40Z</dc:date>
    </item>
  </channel>
</rss>

