Fortran90 issue: nonzero out of bounds array elements

Click For Summary

Discussion Overview

The discussion revolves around an issue encountered in Fortran90 programming related to accessing out-of-bounds array elements. Participants explore the implications of undefined memory access in the context of time-dependent calculations involving arrays.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes an unexpected behavior when accessing an out-of-bounds element C(-3,1) in a complex array, which is not defined in their program, yet produces a curve similar to a defined element C(-2,1).
  • Another participant suggests that reviewing the source code may reveal overlooked issues contributing to the problem.
  • A later reply indicates that resizing the matrix C to include the out-of-bounds index results in a zero value for C(-3,2), implying a relationship to memory management.
  • Another participant emphasizes that accessing undefined memory is problematic and suggests using compiler flags to monitor array bounds during runtime.

Areas of Agreement / Disagreement

Participants express varying views on the nature of the issue, with some attributing it to memory management while others suggest potential coding oversights. No consensus is reached on the exact cause of the behavior.

Contextual Notes

Participants note that the behavior may depend on how memory is allocated and accessed in the program, and there are references to compiler flags that could help identify out-of-bounds access, but specifics on their implementation are not provided.

ilvreth
Messages
33
Reaction score
0
Hi to all.

I am programing a new code for some calculation and i have detected a strange issue.
I have my all arrays strictly defined for example

real, dimension(-2:2,-3:2) A, B
complex, dimension(-2:2,1:2) C

In my time dependend calculations i expect the matrix element C(-2,1) to have a maximum value during the whole run, to be approximately about 1.5 and if you attempt the plot t vs C(-2,1) then the curve seems like a Gaussian.


While i use the ifort and gfortran compilers, i attempted an "experiment" to write the matrix element C(-3,1) (which is NOT defined anywhere initialy in my program... because i have complex, dimension(-2:2,1:2) C and not complex, dimension(-3:2,1:2) C)

The i i descovered that if i plot t vs C(-3,1) then the curve i get is a similar to t vs C(-2,1) which is completely strange because is not defined anywhere so i expect to have zero value every time.

I repeat, every array in my program has been defined bounds as i shown above.

How does it happen??
 
Technology news on Phys.org
A description of what is happening is nice, but it is better to have a look at your source code. There may be another issue which you have overlooked.

If you wish to post your source code, please use the
Code:
 tags.
 
Ok then, I just attempt another experiment which i resize the matrix C from (-2:2,1:2) to (-3:2,1:2) then run the code and you get zero C(-3,2) element. It is about how the memory works i guess. I think this is not a critical issue.
 
Yes, it is a memory thing...the truth is that you have no business with memory that you have not defined...for all we know, it is part of some other program running in your computer.

You should probably look into compiling flags to keep an eye on arrays at run time...something like arraybounds or checkarrays or something like that...then, when you run your program and attempt to access an index outside the defined range, the program will stop and let you know.
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 11 ·
Replies
11
Views
12K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 18 ·
Replies
18
Views
7K
  • · Replies 2 ·
Replies
2
Views
6K
Replies
2
Views
2K
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
17K
  • · Replies 2 ·
Replies
2
Views
9K