Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29255 Discussions

the initial value of variables problem

xxwxxw
Beginner
1,757 Views
I converted the CVF into IVF but when I tried to debug the program there was some problems witht the initial values of variables.
INTEGER N_VTS,HourlyPeriod,DailyPeriod,MonthlyPeriod,
&MIN_HOURLY_PLUS,MIN_Daily_PLUS,MIN_MONTHLY_PLUS,
&Num_Month,Num_Day,Num_Hour
When I bebugged the program, the default values of some of varaibles are zerobut some of themare not. For example, the value of "HourlyPeriod" is37219976. Of cource I should initial these variables before they used. But whyin CVF thedefault value of variables are always zero but things are differen in IVF?Is the setting problem of the project?
Thanks.
xiaowei
0 Kudos
5 Replies
TimP
Honored Contributor III
1,757 Views
The option -Qzero should make initialization to zero by default, but it's not as reliable as correcting the source code.
0 Kudos
Steven_L_Intel1
Employee
1,757 Views
CVF did NOT initialize variables to zero. If you thought it did, it was just a coincidence and not a deliberate action of the compiler.

Intel Fortran does tend to put local scalar variables on the stack so they would be less likely to be zero.

-Qzero helps in some cases, not all. Far better is to fix your program so that it is correct and initializes all variables explicitly.
0 Kudos
Giel_H_
Beginner
1,757 Views

Steve,

I have different findings.

I compared the Compact Visual Fortran (CVF)and Intel Fortran (IVF) initialization in the debugger. I have both Visual Studio Integrated Development Environments (Visual Developer Studio and Visual Studio .Net 2003) on the same PC and Windows operating system (XP Pro).

I debugged the same code as well in CVF (V.6.6C) as IVF (v.9...28; IA32), where the code used in IVF was code that is converted in thedefault wayfrom CVF to IVF.

I noticed that with CVF uninitialized local real and integervariables are set to 0.00.. or 0 and that character values are set to ' '.

With IVF the real variables can be initialized to anything small, typically 1e-38, or occasionally it can be NaN (Not a Number) and mayresultlateroninto an error.Uninitialized integer variables are set to the largest integer value. Character variables are initialized to ' ' or some random string value.

In addition, the debugger shows that in CVF character, real, and integer variablesthat are used locally are implicitly saved.

The debugger shows that in IVF only character variablesthat are used locally are implicitly saved. However, real and integer variablesthat are used locally areNOT saved (unless explicitly saved).

Giel

0 Kudos
Steven_L_Intel1
Employee
1,757 Views
CVF did not deliberately initialize variables to zero. Because CVF defaulted local variables to static storage, in most cases, zero is what you got (character variables would have NULs), but not always. VMS is the only platform where zero initialization was deliberate.

It is true that locals are not implicitly SAVEd in Intel Fortran. The default is that scalar locals go on the stack.

It is a mistake to rely on accidental initialization. Your application should initialize all variables before use. Use SAVE when your application requires it.
0 Kudos
TimP
Honored Contributor III
1,757 Views
Yes, the default storage of CVF was similar to -Qsave in ifort. If you want this behavior, but forgot to put SAVE in your source code, maybe you should consider that step toward correctness.
0 Kudos
Reply