Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

index loop variable is kept constant

Status
Not open for further replies.

gatormm

Technical User
Jan 2, 2009
2
I keep running into strange bugs while working on an ongoing project written in Fortran 77. In this bug, one the index variables in a loop is staying fixed at 1.

In my main program is a three-level nested do loop. Three double precision variables, are set to the values of of i,j,k in each iteration. These represent coordinate in space which will be used to sample the output of two particular functions referenced below.

some code:

do k=1,ndim
do j=1,ndim
do i=1,ndim

ri = DBLE(i)
rj = DBLE(j)
rk = DBLE(k)

call bumpy_img_one(ri,rj,rk,f_one_int,hold)
call bumpy_img_two(ri,rj,rk,r_two_int,hold)

...

The running program hung before this loop terminated because the value of k was not changing (the integer value k remained 1 for all iterations) and the behavior is dependendent on whether or not bumpy_img_two and bumpy_img_one is commented out. Bumpy_img_one actually calls bumpy_image_two in its implementation.

I could have sworn that when I first detected this bug only bumpy_img_two was causing the bug and considering what I wrote above this struck me as very strange. I checked again while writing this post and it now appears both cause the bug. The bummpy_img proecuedures are called once before the do loop is initiated and removal of these lines also remove the bug.

In the bumpy_image_two subroutine there is a single line which when commented out turns off the bug. In this line the 3rd and final element of a double precision array g is initialized to 0. In the main program the three element double precision array hold is passed into both bumpy_image routines and used as a dummy variable since this part of the program does not need to keep the output, normally g, at this point in the program.

I've run into similar strang bugs in fortran before and I get lucky and they just seem to disappear as quickly as thay appear. In fact, the code where this bug is now occuring is more than 5 months old but the bumpy_image routines have displayed strange bugs before.

The program is being compiled with the Intel Fortran Compiler on an Ubunutu 8.10 installation. The Installation is being run from a virtual machine (Sun VirtualBox). I thought maybe there were issues with the virtual machine not having enough memory but that had no noticeable affect on this error.

How do I specifically go about solving a bug like this. Furthermore, how can I prevent them. I will appreciate any and all feedback as I feel very out of my league.

Regards to all who read the post,

Matt
 
In bumpy_img_one etc, how are ri, rj and rk declared?

I don't know how IVF does its reals. Some compilers use real*1, real*2, real*3; others use real*4, real*8, real*16.

Real*8 or real*2 should be equal to double precision.
 
Inside the bumpy_img routines, ri,rj,rk are called rx,ry,rz and are double precision. In fact, every variable in all parts of my program are declared double precsision if they are not inteded to ever have integer values or unless they will be used to hold input from a real data source. So whatever the exact format is for double's in this case, its being consistently used everywhere. So ri,rj,rk in the Main Routine have the same type ad rx,ry,rk in the bumpy_img_routines as does hold in the main program. The index variable is explicitly defined in the main routine as an integer.

 
The only thing I can think of is a local array going out of bounds. Something like this
Code:
real*8, dimension(10):: walkies
walkies(13) = 1.0
If IVF has array range checking, try switching that on and see if flags anything.

The other alternative is typos. At the head of every routine add implicit none and declare every variable you use. This is a pain but it helps you get out of typos.

Have you checked for obvious ones like
Code:
do 10 i=1.5
  ...
10 continue
You can get around these by always specifying the increment because these are both illegal and will be picked up by the compiler
Code:
do 10 i=1.5,1
do 10 i=1,5.1
The alternative is to use do..enddo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top