Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
13 Views

Very large dynamically allocated arrays in COMMON

Jump to solution

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

Accepted Solutions
Highlighted
13 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
Highlighted
14 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
Highlighted
Beginner
13 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
Highlighted
13 Views

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

Jim Dempsey

0 Kudos