Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
21 Views

RECURSIVE and SAVE

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
Highlighted
Black Belt
21 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
Highlighted
21 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