<?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: Initialization of local variables in subroutines in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826033#M50080</link>
    <description>&lt;P&gt;Under the f77 standard, IBM MVS Fortran took advantage of the option to not automatically SAVE variables defined in DATA.In fact, such variables would be reset automatically to the DATA values. So, even back then, it was necessary to use SAVE on all local variables where your program requires it according to the standard. Only with extreme luck would an incorrect program have run the same on IBM MVS Fortran and on compilers with default SAVE. I can't see how a newer IBM Fortran would have eliminated the requirement for correct use of SAVE.&lt;/P&gt;
&lt;P&gt;So, in this situation, the recommendation to avoid relying on compile flags for default SAVE would have even more force than usual.&lt;/P&gt;
&lt;P&gt;Not to mention the requirement for an optimizing or parallelizing compiler to detect weird dependencies arising from standard violations, and disable optimizations accordingly.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Mar 2007 16:27:32 GMT</pubDate>
    <dc:creator>TimP</dc:creator>
    <dc:date>2007-03-07T16:27:32Z</dc:date>
    <item>
      <title>Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826029#M50076</link>
      <description>&lt;P&gt;I am porting a large application from IBM MVS to IBM PC using the Intel FORTRAN compiler in batch mode, alsoIntel FORTRAN compiler forwindows mode. On the IBM MVS initialized local variable values within a subroutine are preserved upon subsequent calls to that subroutine, and on the IBM PC initialized local variable values are not preserved and are set to zero upon subsequent calls to that subroutine. Sample illustrative code is listed below. My question is the following: Is there a run time option to save the initialized local variable values for subsequent calls to a subroutine? The local varibles that need their values preserved should probably be placed into a COMMON statement.&lt;/P&gt;
&lt;P&gt;Geoff Grosguth&lt;/P&gt;&lt;PRE&gt; PROGRAM TEST&lt;BR /&gt;C 1 2 3 4 5 6 7&lt;BR /&gt;C23456789012345678901234567890123456789012345678901234567890123456789012&lt;BR /&gt;C TEST TO SEE IF LOCAL VARIABLES WITHIN A SUBROUTINE ARE INITIALIZED&lt;BR /&gt;C EACH TIME THE SUBROUTINE IS CALLED WHEN USING THE INTEL FORTRAN &lt;BR /&gt;C COMPILER&lt;BR /&gt; INTEGER*4 I&lt;BR /&gt; INTEGER*4 GCCMD&lt;BR /&gt; COMMON /FLAG/ GCCMD&lt;BR /&gt; OPEN (UNIT=6) &lt;BR /&gt;C&lt;BR /&gt; CALL CALC()&lt;BR /&gt;C&lt;BR /&gt; STOP&lt;BR /&gt; END&lt;/PRE&gt;&lt;PRE&gt; SUBROUTINE CALC()&lt;BR /&gt; INTEGER*4 NUM&lt;BR /&gt; INTEGER*4 GCCMD&lt;BR /&gt; COMMON /FLAG/ GCCMD&lt;BR /&gt;C&lt;BR /&gt; GCCMD = 1&lt;BR /&gt; CALL CALC2()&lt;BR /&gt;C&lt;BR /&gt; GCCMD = 2&lt;BR /&gt; DO 10 I = 1, 10&lt;BR /&gt; CALL CALC2()&lt;BR /&gt; 10 CONTINUE&lt;BR /&gt;C&lt;BR /&gt; RETURN&lt;BR /&gt; END&lt;/PRE&gt;&lt;PRE&gt; SUBROUTINE CALC2()&lt;BR /&gt; INTEGER*4 NUM&lt;BR /&gt; INTEGER*4 GCCMD&lt;BR /&gt; COMMON /FLAG/ GCCMD&lt;BR /&gt;C&lt;BR /&gt; IF (GCCMD .EQ. 1) THEN&lt;BR /&gt; NUM = 89&lt;BR /&gt; WRITE(UNIT=6,FMT='(A,I5)') ' NUM21=', NUM&lt;BR /&gt; ELSEIF (GCCMD .EQ. 2) THEN &lt;BR /&gt; WRITE(UNIT=6,FMT='(A,I5)') ' NUM22=', NUM&lt;BR /&gt; ENDIF&lt;BR /&gt;C&lt;BR /&gt; RETURN&lt;BR /&gt; END&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Mar 2007 20:01:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826029#M50076</guid>
      <dc:creator>grosguth</dc:creator>
      <dc:date>2007-03-01T20:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826030#M50077</link>
      <description>Local variables that need to be preserved should be named in a SAVE statement. You can use the /Qsave command line option (in Visual Studio, this is under Fortran..Data..Default storage for local variables - All variables SAVE, but I consider this a poor substitute for correcting the bug in the code that failed to properly SAVE local variables.</description>
      <pubDate>Thu, 01 Mar 2007 21:04:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826030#M50077</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-01T21:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826031#M50078</link>
      <description>I don't quite follow your problem. &lt;BR /&gt;&lt;BR /&gt;Any variable you initialize with a DATA statement, or any variable in COMMON, or any variable explicitly mentioned in a SAVE statement, it will be saved from call to call.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any other variable is liable to lose its value, as per the standard I think.&lt;BR /&gt;&lt;BR /&gt;Now IVF tends to lean toward making variables AUTOMATIC, which saves on memory but tosses variable values. Such is the price of progress.&lt;BR /&gt;&lt;BR /&gt;So as you hinted, you can add SAVE statements, or put the variables in COMMON, or use the compiler option to force static variables as a temprary resort.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Mar 2007 21:25:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826031#M50078</guid>
      <dc:creator>grg99</dc:creator>
      <dc:date>2007-03-06T21:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826032#M50079</link>
      <description>Correction - COMMON variables, if you want to be standard conforming, need SAVE. Most implementations don't require this, but if the common isn't always "active" in the call chain, the standard allows the values to become undefined. Same with module variables.</description>
      <pubDate>Tue, 06 Mar 2007 22:03:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826032#M50079</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-06T22:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826033#M50080</link>
      <description>&lt;P&gt;Under the f77 standard, IBM MVS Fortran took advantage of the option to not automatically SAVE variables defined in DATA.In fact, such variables would be reset automatically to the DATA values. So, even back then, it was necessary to use SAVE on all local variables where your program requires it according to the standard. Only with extreme luck would an incorrect program have run the same on IBM MVS Fortran and on compilers with default SAVE. I can't see how a newer IBM Fortran would have eliminated the requirement for correct use of SAVE.&lt;/P&gt;
&lt;P&gt;So, in this situation, the recommendation to avoid relying on compile flags for default SAVE would have even more force than usual.&lt;/P&gt;
&lt;P&gt;Not to mention the requirement for an optimizing or parallelizing compiler to detect weird dependencies arising from standard violations, and disable optimizations accordingly.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2007 16:27:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826033#M50080</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2007-03-07T16:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826034#M50081</link>
      <description>Note that in Fortran 90 and later, variables initialized with DATA (and in most cases initialization in the declaration) have the SAVE attribute implied by the language standard.</description>
      <pubDate>Wed, 07 Mar 2007 17:54:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826034#M50081</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-03-07T17:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826035#M50082</link>
      <description>&lt;P&gt;I've seen initializations done as in &lt;/P&gt;
&lt;P&gt;:&lt;/P&gt;
&lt;P&gt;real x&lt;/P&gt;
&lt;P&gt;:&lt;/P&gt;
&lt;P&gt;x = x ! first reference to x&lt;/P&gt;
&lt;P&gt;Is this OK andhow does a compilerhandle it? How about x=sin(x)? Is this guaranteed toinitialize x to 0 (or +/- pi, 2pi, etc ) or what?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2007 01:41:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826035#M50082</guid>
      <dc:creator>g_f_thomas</dc:creator>
      <dc:date>2007-03-09T01:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826036#M50083</link>
      <description>No, it does nothing of a sort. The X is still uninitialized. &lt;BR /&gt;&lt;BR /&gt;Actually, I've seen the "x=x" trick only in the contexts where x is a dummy argument required by the environment (e.g. of a callback routine) but the routine does not want to use it. In that case, "x=x" is a nice try to stop compiler warning about "unused variable" (which doesn't work in e.g. release version with some IVF versions, where the compiler first optimizes out "x=x" and then proceeds to complain about the unused variable &lt;IMG src="https://community.intel.com/isn/Community/en-US/emoticons/emotion-4.gif" alt="Smiley with tongue out [:-P]" /&gt;). I don't know the current status of such "feature" in IVF.&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Mar 2007 09:40:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826036#M50083</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2007-03-09T09:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826037#M50084</link>
      <description>&lt;P&gt;Ah, wherever I saw x = x had nothing to do with initializing. Good, I wouldn't do it either. It's use to not use is cute.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2007 15:41:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826037#M50084</guid>
      <dc:creator>g_f_thomas</dc:creator>
      <dc:date>2007-03-09T15:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Initialization of local variables in subroutines</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826038#M50085</link>
      <description>&lt;P&gt;G,&lt;/P&gt;
&lt;P&gt;x = x may be a convient spot to place a break point in the Debug configuration, easy to eyeball in the source file, gets optimized out in the Release version. No need for "uggly" conditional compilation directives. Personally I prefer to use the preprocessor and #define statements to "sparkle" the code with diagnostics.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2007 16:11:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Initialization-of-local-variables-in-subroutines/m-p/826038#M50085</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2007-03-09T16:11:03Z</dc:date>
    </item>
  </channel>
</rss>

