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

Strange behavior regarding DIMENSION statements

boxyzzy
Beginner
845 Views

I am a Sys Admin. I do NOT know FORTRAN. However, I am seeking your guidance regarding "FORTRAN 10.0.023" on behave of a researcher who reports to me that changing only the DIMENSION statement defining the size of an array results in different/unexpected computed values. From our perspective, an algorithm using an array size of, say, 100, should work exactly the same for an array size of, say 100000, for those 100 elements.

All suggestions are welcomed,

Mike

0 Kudos
7 Replies
Ron_Green
Moderator
845 Views
Mike,

Unfortunately, there are a lot of good reasons why changing array dimensions can change results.

We don't have enough to go on here. Could you encourage your user to get onto the Forum and provide his code and details? There is no reason why he can't post on this Forum, it is open to everyone.

ron
0 Kudos
boxyzzy
Beginner
845 Views
Ron, thanks for your comments.

I will encourage him to join this forum of programmers.

In the meantime, I share the following information:
The first DIMENSION statement below is the one that seems to cause the problem - unexpected results.
If I change the 1000000 to 100000 to produce the second statement, then it works as expected.

DIMENSION SDSS1V(0:402, 1000000), SDSS2V(0:402, 1000000)
DIMENSION SDSS1V(0:402, 100000), SDSS2V(0:402, 100000)

Are there memory management statements and/or compile options that need to be introduced?


Thanks,

Mike
0 Kudos
TimP
Honored Contributor III
845 Views
Now you are talking about 403,000,000 elements in an array. Even for default real or integer data types, this would use up most of the virtual address space available, if you are running in 32-bit mode.
0 Kudos
jimdempseyatthecove
Honored Contributor III
845 Views

>>Now you are talking about 403,000,000 elements in an array

And he has at least 2 of these arrays. 806,000,000 * 4 or * 8 if REAL(8)

3.2GB or 6.4GB. This does exceed virtual memory max on 32-bit system and may exceed static data limits and stack limits on 64-bit systems. The variable would generally have to be allocatable (not static nor stack based). Heap array option would work for stack local declared array if you did not want to use allocatable arrays.

Jim

0 Kudos
boxyzzy
Beginner
845 Views

Thanks for your comments and for better defining the situation.

This is a 64-bit system.

Can someone explain, offer examples, and /or point to documentation to implement:

1) an allocatable array

2) heap array

Mike

PS Is there a forum for Sys Admins? I have a seperate unrelated issue for which I need guidance.

0 Kudos
joseph-krahn
New Contributor I
845 Views
boxyzzy:

Thanks for your comments and for better defining the situation.

This is a 64-bit system.

Can someone explain, offer examples, and /or point to documentation to implement:

1) an allocatable array

2) heap array

Mike

PS Is there a forum for Sys Admins? I have a seperate unrelated issue for which I need guidance.


Fortran standards do not define how arrays are allocated, so there can be differences among compilers. An allocatable array is similar to an array allocated with maoolc() in C, except that it is automatically freed when the allocatable variable goes out of scope.

I think that a "heap array" probably refers to a statically allocated array, defined in the main program or a common block. A common block is a contiguous block of memory that represents several variables, and can be defined differently in different scopes.

Another type of array is an automatic array, which is a variable-sized array defined within a procedure. It is often allocated from the stack, but can also come from allocated storage, depending on the coimpiler, array size, and compile options.

As for the array dimensioning problem, it is important to realize that arrays are strided in the opposite order from C. By redimensioning the first dimension, the members get a different stride, rather than just reducing the array size. If this array is passed to a routine that has a fixed first-dimension, elements will get mixed up. With Fortran77, procedures have to define dimensions themselves from arguments or constants. With Fortran90, arguments can be passed by an array reference that contains the dimensions, but the caller has to have an explicit interface via a module or INTERFACE block.
0 Kudos
joseph-krahn
New Contributor I
845 Views
boxyzzy:

PS Is there a forum for Sys Admins? I have a seperate unrelated issue for which I need guidance.


If you have an Admin question related to Fortran, just ask it here. Fortran does not have well-organized conventions. For example, people working with modules tend to put public binary .mod files in either /usr/include or /usr/lib, both of which are wrong. Fortran has no ABI or file-format standards, so they are application-specific files and should go somewhere like /usr/lib/ifort-10.0.
0 Kudos
Reply