- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a user with a huge CFD grid and found out the code he was running was having a problem with an integer*4 variable getting too large. I changed the variable to an integer*8 value, but the code still did not work. I then used -check bounds and saw a large negative number displayed when the program stoped and said the array was out of bounds.
so the question is, can I use an integer*8 variable as an array subscript?? Is there a way to do this or a compiler option.
thanx in advance,
Bernie
the boeing company
so the question is, can I use an integer*8 variable as an array subscript?? Is there a way to do this or a compiler option.
thanx in advance,
Bernie
the boeing company
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
integer(kind=8) is valid for Fortran subscripts. However, it won't help you unless you are running a 64-bit compiler, either using appropriate mcmodel options or allocatable arrays. If the code expects default integer to be 64-bits, there is an option for that. You would need to take care not to mix integer types in a way not foreseen by the developer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To expand on what TimP is saying:
It is advisable to create an index parameter
INTEGER, PARAMETER :: BigArrayIndex = 8 ! place in some module
ChangeBigArrayIndexto whatever you want.
Then
SUBROUTINE YourSubroutine(N,...)
USE ModuleContainingBigArrayIndex
INTEGER(KIND=BigArrayIndex),INTENT(IN)::N
INTEGER(KIND=BigArrayIndex) :: I, J ...
...
DO I=1,N
...
BigArray(I) = expression
...
Your work is not done yet
You need to Find In Files all references to:
BigArray
and
YourSubroutine
to assure that the users of BigArray and callers to YourSubroutine are also using
INTEGER(KIND=BigArrayIndex) ::...
variables or
12345_BigArrayIndex
literals
Failure to do so may generate negative orhigh bit truncated positive indexes
TimP also mentioned the use of setting the default integer type to 8. However this will not address the issues relating to integer variables declared as INTEGER(4) or other ways of declaring lesser than 8 bytes of integer precision.
Jim Dempsey
It is advisable to create an index parameter
INTEGER, PARAMETER :: BigArrayIndex = 8 ! place in some module
ChangeBigArrayIndexto whatever you want.
Then
SUBROUTINE YourSubroutine(N,...)
USE ModuleContainingBigArrayIndex
INTEGER(KIND=BigArrayIndex),INTENT(IN)::N
INTEGER(KIND=BigArrayIndex) :: I, J ...
...
DO I=1,N
...
BigArray(I) = expression
...
Your work is not done yet
You need to Find In Files all references to:
BigArray
and
YourSubroutine
to assure that the users of BigArray and callers to YourSubroutine are also using
INTEGER(KIND=BigArrayIndex) ::...
variables or
12345_BigArrayIndex
literals
Failure to do so may generate negative orhigh bit truncated positive indexes
TimP also mentioned the use of setting the default integer type to 8. However this will not address the issues relating to integer variables declared as INTEGER(4) or other ways of declaring lesser than 8 bytes of integer precision.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
and to continue on this, many OSes still limit static arrays to 2GB. So make sure your arrays are ALLOCATABLE and not dusty old static arrays in COMMON blocks.
ron
ron
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page