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

Run-time error connected to WRITE(*,*) without -check?

dsokus
Beginner
391 Views
For part of a simulation program I am writing I need to give values to elements of integer arrays (all of them are declared as allocatable in the beginning, and all of them are allocated by this part of the program).

I noticed that the final values weren't what I was expecting so I added WRITE(*,*) statements in different places in my program to be able to find out where the assignments went wrong. However, with these statements in, all the values came out all right. I !-ed some of the WRITE-s, recompiled and the values went wrong again. I repeated this a couple of times and it was consistently so... Then I added the -check option while compiling and I got no error messages, but the values are fixed again.

This leaves me puzzled. Now the program seems to work, but since it involves random numbers it can hide a lot of errors in its results if it doesn't crash from them - I would really like to understand what the problem is/was.

Thanks,
Zsuzsi

Here's part of the code:

----
do k = 1, n
barsx(k) = k
barsy(2,k) = 0

do walking = 1, totwalk
write(*,*) 'W: walker no ', walking, ' at time ', k, ' has position ', yray(walking,k)
write(*,*) 'W2: walker no ', walking, ' at time ', chosen, ' has position ', yray(walking,chosen)
if (yray(walking,chosen).eq.k) barsy(2,k) = barsy(2,k) + 1
end do

end do
----

Without the -check option, if the first WRITE is !-ed, the output is

W2: walker no 1 at time 5 has position 5
W2: walker no 2 at time 5 has position 5
W2: walker no 3 at time 5 has position 5
...
(and the same for all the rest, which is obviously wrong)

Leaving the first WRITE in, it is

W: walker no 1 at time 1 has position 1
W2: walker no 1 at time 5 has position 2
W: walker no 2 at time 1 has position 1
W2: walker no 2 at time 5 has position 3
W: walker no 3 at time 1 has position 1
W2: walker no 3 at time 5 has position 1
...
0 Kudos
2 Replies
Steven_L_Intel1
Employee
391 Views
This is a typical symptom of use of uninitialized variables. Anything that changes instructions or moves data around can change the symptom.
0 Kudos
dsokus
Beginner
391 Views
Thanks. I looked again and got down to re-doing the entire declaration/allocation/initialization stuff; then compiled and the problem stopped. I still don't know what I missed out before but now it's finally working reliably.
0 Kudos
Reply