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

local variables do not release on time

Wang_J_
Beginner
1,074 Views

One section of my program is a module with many subroutines. In each subroutine there the same integer variables like 'i,j,k,m'. These variables are used to control the loops in each subroutine,such as ‘do i=1,10’; or used to save some temporary values.  I am sure that there are no 'common' or 'save' in my program. But when the program runing from one subroutine to another, these variable can not be changed. For example, I change k as 'k=1', it is still the former value. So i delete these variables in the subroutines and directly declare them in the module. Then, it worked well. I know the variables in subtoutine are local variables. why i can not  change them? 

0 Kudos
12 Replies
mecej4
Honored Contributor III
1,074 Views
For example, I change k as 'k=1', it is still the former value.
How did you check this? If you used a symbolic debugger to do so, note that if you have optimization enabled some variables may be handled entirely in registers, or the value in memory and the value in a register may not be synchronized.
0 Kudos
Wang_J_
Beginner
1,074 Views

mecej4 wrote:

Quote:

For example, I change k as 'k=1', it is still the former value.

How did you check this? If you used a symbolic debugger to do so, note that if you have optimization enabled some variables may be handled entirely in registers, or the value in memory and the value in a register may not be synchronized.

 I just debug the program in VS2010 and use the watch window to monitor their values. Sometimes it can not be changed. For a short programm, it will always work well. But for a long one, this mistake will happen occassionally.

0 Kudos
Wang_J_
Beginner
1,074 Views

mecej4 wrote:

Quote:

For example, I change k as 'k=1', it is still the former value.

How did you check this? If you used a symbolic debugger to do so, note that if you have optimization enabled some variables may be handled entirely in registers, or the value in memory and the value in a register may not be synchronized.

 I just debug the program in VS2010 and use the watch window to monitor their values. Sometimes it can not be changed. For a short programm, it will always work well. But for a long one, this mistake will happen occassionally.

0 Kudos
Andrew_Smith
Valued Contributor I
1,074 Views

Can we see a complete code example showing the problem please

0 Kudos
Wang_J_
Beginner
1,074 Views

Andrew Smith wrote:

Can we see a complete code example showing the problem please

the program is for numerical simulation and it too long. it also need the data file to run smoothly. I use another complier to debug the program, the mistake disappeared. So maybe i did not install the complier properly.

0 Kudos
TimP
Honored Contributor III
1,074 Views

Fortran doesn't permit changing a loop control variable inside the loop.  Ideally, the compiler gives you a diagnosis when you attempt to violate the rule.  If you succeed in changing it without being caught, the program behavior is undefined.

As others hinted, it would be important to give an example to clarify your meaning.

0 Kudos
Wang_J_
Beginner
1,074 Views

TimP (Intel) wrote:

Fortran doesn't permit changing a loop control variable inside the loop.  Ideally, the compiler gives you a diagnosis when you attempt to violate the rule.  If you succeed in changing it without being caught, the program behavior is undefined.

As others hinted, it would be important to give an example to clarify your meaning.

i did not change the a loop control variable inside the loop.  i just mean it did not increase an it will be. 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,074 Views

integer :: i
i = 1 ! ok outside of loop using i as loop control variable
DO i=1,N
i = i + 2 ! Not valid to do this inside loop, either with debugger or by code
...
END DO

Note, if any compiler optimizations occure, then the variable i may have a location (stack variable) when the code is outside the loop, and may reside inside a register when inside the loop. Under conditions when the loop control variable is in a register, the debugger may not permit you to alter its value (which is invalid for you to do so whether i is located in a register or not). Depending on debugger and compiler version, it may indicate that i is inside a register.

Jim Dempsey

0 Kudos
Wang_J_
Beginner
1,074 Views

module aaa                                                                                                                                                                                                                     subroutine b1                                                                                                                                                                                                                  integer i,j,k                                                                                                                                                                                                        do i=1,30...                                                                                                                                                                                                    end subroutine                                                                                                                                                                                                                     subroutine b2                                                                                                                                                                                                                  integer i,j,k                                                                                                                                                                                                        do i=1,30...                                                                                                                                                                                                    end subroutine                                                                                                                                                                                                                     subroutine b3                                                                                                                                                                                                                  integer i,j,k                                                                                                                                                                                                        do i=1,30...                                                                                                                                                                                                    end subroutine                                                                                                                                                                                                                  end module                                                                                                                                                                                                               

When i called subroutine b1,everything is ok, but when i called b2, the value of 'i' is still the previous value obtained when return form b1.  Even if i use 'i=1', the value of 'i' still can not be changed.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,074 Views

Insert a

WRITE(*,*) i

After each DO in each DO loop and see what comes out.

If you compile with any optimizations enabled then i may be registerized.
Also, if i is not used in the loop or elsewhere outside the loop, then a no optimization might concievably remove i since it wouldnever be referenced (FORTRAN DO loops compute an iteration count as opposed to performing a limit test using the loop control variable).

Jim Dempsey

0 Kudos
Andrew_Smith
Valued Contributor I
1,074 Views

I dont think anyone can understand your issue without posting meaningful code. Your code does not have any assignments such as was your stated problem and none of the subroutines are called.

0 Kudos
Wang_J_
Beginner
1,074 Views

Thank you for your insightful comments. Maybe the code is too simple to find out the ture reason,and i have solved this porblem by changing the version of my complier. So if i come acorss the problem again, i will give a more detail codes. Thank you very much.

0 Kudos
Reply