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

intent statement for scratch arrays

Jarek_T
Novice
492 Views

While documenting and modernizing 30 year old fortran 77 code, I do a lot of figuring out what are inputs and outputs to each subroutine and documenting my findings by adding "intent" statements.  I understand in, out and inout intents, but I am a bit confused how to label intent of scratch arrays, which are  neither input or output.  

 

I think the original programmer was trying to save precious memory space by reusing no longer needed large statically allocated arrays  as as scratch space for subsequent subroutines and we do not care about neither input or output of those subroutines. 

 

I realize that probably the best approach is to rewrite the code, so we do not use them, if I find such arrays is there a way to label them as scratch space? 

0 Kudos
1 Reply
andrew_4619
Honored Contributor III
466 Views

intent is maybe a bad name, it serves two purposes IMO as you describe it documents, but it is also a safety guard that stops you passing constants and then trying to modify them and can allow the compiler to see instances when intent out variables are not initialised etc. so it prevents some types of bug.

 

But if you pass and array and partially modify it a bit in any way it is intent(inout) irrespective of if it is junk in junk out scratch space.

I quick solution for large scratch spaces is to allocate the space in the subroutine and it automatically gets deallocated on exit then all is clear. 

0 Kudos
Reply