(j3.2006) implicit deallocation in main programs

Bill Long longb
Tue Sep 13 18:10:31 EDT 2011



On 9/13/11 1:38 AM, Robert Corbett wrote:
> Oracle's Fortran team received a bug report today
> claiming that unsaved allocatable variables in main
> programs should not be implicitly deallocated.

There is no such thing as an unsaved allocatable variable declared in 
the main program.


> Oracle Solaris Studio (OSS) Fortran does implicitly
> deallocate unsaved allocatable variables in the main
> program if execution reaches the END statement of
> the main program.  I think our implementation is
> standard conforming, because it is impossible to tell
> from within a program that the variable has been
> deallocated.  Does anyone think I am incorrect?

The question is really whether the implementation returns the memory for 
saved allocatable variables.  The END statement at the end of the main 
program (or a STOP statement) should result in entering the global 
program termination barrier.  Before you get to that barrier,  you may 
not delete any memory used for a variable that is either a coarray, has 
the TARGET attribute, or is an allocatable component of a coarray 
structure.  Otherwise it would not be accessible to other images that 
have not yet stopped. The simplest implementation is to just not delete 
any memory at this stage.  Once all of the images have completed 
execution of the termination barrier,  no Fortran statement can be 
executed that would be able to reference of define these (or any other) 
variable in the program, so what you do is immaterial.  Ultimately, the 
OS will require (or at least highly prefer) that the memory you were 
using be returned to its available pool.  If that's done through the 
deallocate library routine, that's fine.  The Fortran requirement hinges 
on when that happens - after the termination barrier has completed.

In a subsequent email from Bob:

 >The people who reported the bug are developing a tool for
 >detecting memory leaks.  Their tool would have detected a
 >leak in their sample program if we had not done the
 >deallocation.

It would seem that the tool would have a similar problem with any 
allocatable array with the SAVE attribute.  If the tool is to be useful 
for Fortran programs, it needs to either be able to know about SAVE, or 
run a final pass as part of the "return memory to the OS" stage of 
termination.

Cheers,
Bill

>
> Note that we have not yet implemented finalizers,
> so we have not yet made the mistake of running the
> finalizers when the END statement is reached.
>
> Bob Corbett
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3

-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list