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

Can I use an integer*8 variable to subscript an array

Bernie_B_
Beginner
1,376 Views
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
0 Kudos
3 Replies
TimP
Honored Contributor III
1,376 Views
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.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,376 Views
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
0 Kudos
Ron_Green
Moderator
1,376 Views
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
0 Kudos
Reply