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

RECURSIVE and SAVE

LRaim
New Contributor I
264 Views

I am beginning to review some core subroutines of my simulation applications with the aim to introduce some parallelization (now I use only PARDISO) which must be based on subroutine calls in parallel DO or parallel blocks.
​In doing this I have added the RECURSIVE keyword to a SUBROUTINE containing a SAVE statement which is not coherent.
Surprisingly the compiler has generated no warning or error messages.

 

 


 

 

0 Kudos
2 Replies
TimP
Honored Contributor III
264 Views

The compiler doesn't check whether your usage of SAVE will pose a problem for recursive or parallel execution.  If you don't assign to the SAVE variable in multiple threads, or use it in a parallel region where another thread assigns to it, it should be OK.  RECURSIVE does prevent the compiler from giving any local variables or arrays an effective SAVE status without a SAVE declaration.

0 Kudos
jimdempseyatthecove
Honored Contributor III
264 Views

There is nothing inherently wrong with recursive and SAVE. An example is for the SAVE to contain once-only initialized data, either initialized via a call made from the serial section or with use of a critical section when initialized while in a parallel region. You would not SAVE general working data.

Caution, do not blindly remove the SAVE without looking at the code. If the SAVE'd variables require persistence across calls, then you will have to figure out how to safely convert the SAVE'd variables .OR. use in thread-safe manner.

Hint:  blindly remove the SAVE == making a simple test and assuming it is safe to remove if the simple test indicates OK. This will catch you off guard if the race (or conflict) condition occurs infrequently.

Jim Dempsey

0 Kudos
Reply