I was writing a subroutine that would verify the size of an allocatable array
and if necessary reallocate it with the requested size. It was also going to
support flags for things like "copy the old data to the new array instantiation"
"if you need to expand the array over-expand it by a requested percentage" etc.
The arrays in questions would usually be defined in modules that were use
associated to the computational routines.
If you are a real Fortran guru you are now giggling at my naivite....
-------------
It turns out that the Fortran 95 standard explicitly says that a dummy argument
can not have the ALLOCATABLE attribute. So much for that good idea of mine. I
have come to the conclusion that I could do:
1) In the module I can define a module procedure that deallocates/reallocates
through host association. Or I could use associate the array to a procedure
that does the assertion/expansion.
2) I could make the dummy argument a POINTER array and the base array a TARGET
--
The solution 1) requires one unique subroutine for each array where each routine
would be indentical except for the name and the statement
use array_module, ONLY: REAL_ARRAY_NAME => DUMMY_ARRAY_NAME
The subroutine body would use the alias DUMMY_ARRAY_NAME for the actual array
REAL_ARRAY_NAME. Also the name array_module would be different between different
instantiations of the subroutine.
This should be possible although somewhat awkward. (Although using m4 or CPP
would probably make it ok)
The solution 2) should work out-of-the-box, but I am somewhat afraid that
compilers might be more restrictive when optimizing arrays with the TARGET
attribute.
In F2K I assume that I could tie such a verify/expand subroutine to a
base type and derive my arrays from that type.
--
I have two questions:
Firstly: Does anyone know what lies behind the standard explicitly stating that
a dummy argument must not have the ALLOCATABLE attribute? I am having problem
seeing good reasons why the restriction would be necessary. At least in the
sense that a compiler can take much use of this. Any function and or subroutine
call (that is not pure) can still have the side effect that arrays move in memory
or expand/shrink since it is possible do it by host/use association.
Secondly: Have anyone made investigations as to what extent POINTER and TARGET
attributes affects the optimizing compilers on the market?
Best regards,
/Nils
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Nils Smeds (formerly Jönsson) http://www.pdc.kth.se/
Center for Parallel Computers e-mail: [log in to unmask]
Royal Institute of Technology Voice: +46-8-7909115
KTH Fax: +46-8-247784
S-100 44 Stockholm, Sweden Office: OB2, room 1546
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|