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

Very large dynamically allocated arrays in COMMON

e013805
Beginner
318 Views

I have a large 32 bit FORTRAN program (using the Intel 11.1.072 FORTRAN compiler) that has been in development for many years.  The program has two versions, a "batch" version (all FORTRAN) and an interactive version which uses a JAVA interface (and in the near future a C or C++ interface).

The program currently uses an essentially home grown dynamic memory allocation using a very large common real number array (dimension 144,000,000) but I am at the 2 Gb limit for program plus data and need more storage space.  So I switched to x64 and dynamic memory allocation to "fix" my problem hoping to make only modest changes to the code (which contains many, many, many thousands of lines).  The earlier code had a common like this:

      REAL E( 1200 : 144001200 )

      COMMON / MEMORYR / E

The new code looks like this:

      POINTER             E(:)

      COMMON  /MEMORYP/  E

So the main program now has these statements:
 

      POINTER             E(:)

      COMMON  /MEMORYP/  E

     ALLOCATABLE   EE(:)
      TARGET        EE

      K_N = K_MAX_ARRAY_SIZE  +  1200
      ALLOCATE(  EE( 1200 : K_N ) )

       E  =>  EE

And the batch version (where a large number of subroutines access the E "array") works just fine.  The problem is that as near as I have been able to determine, the above statements MUST be in the main program, my attempt at putting them in a subroutine did not work.  And there lies the issue.  If those statements indeed must be in the main program, how can I put them in JAVA (or C or C++) for the interactive version of the program to work??

Any light you can shed on this would be greatly appreciated

 

0 Kudos
1 Solution
Steven_L_Intel1
Employee
318 Views

If I understand what you have done, the solution is to change the declaration of EE to:

ALLOCATABLE, SAVE :: EE(:)

(You could add in the TARGET attribute here if you want.)

The reason is that ALLOCATABLE variables that are local to a routine, and do not have the SAVE attribute, are automatically deallocated when the routine exits. Adding SAVE prevents that deallocation.

View solution in original post

0 Kudos
3 Replies
Steven_L_Intel1
Employee
319 Views

If I understand what you have done, the solution is to change the declaration of EE to:

ALLOCATABLE, SAVE :: EE(:)

(You could add in the TARGET attribute here if you want.)

The reason is that ALLOCATABLE variables that are local to a routine, and do not have the SAVE attribute, are automatically deallocated when the routine exits. Adding SAVE prevents that deallocation.

0 Kudos
e013805
Beginner
318 Views

Right you are Steve.  I cannot thank you enough, your solution worked perfectly!  Being an OLD, OLD FORTRAN programmer, the dynamic allocation would have worked well from the beginning on this program (started in the early 90's on a Cyber mainframe) had it been available, but we had to make do with what we had at the time.  Thanks again!

0 Kudos
jimdempseyatthecove
Honored Contributor III
318 Views

You can also allocate a pointer (no need for EE).

Jim Dempsey

0 Kudos
Reply