- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am solving a set S1 of nonlinear equations, where some of these nonlinear equations involve the solutions of another set S2 of nonlinear equations.
So, assuming that my main solver subroutine is SOLVE, my program will call SOLVE(S1), which in turn (at some point)will require a call SOLVE(S2).
This looks like a recursive call - except that there are several levels of nested subroutines between the S1 and S2 problems.
Obviously there is a conflict when SOLVE(S2) is called - as its local variables will erase the one needed for the SOLVE(S1) call.
Is there a convenient way to get around this? The obvious choice is to duplicate (with different names) the subroutines involved in my solver; but that certainly does not look very elegant...
Thanks,
Olivier
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
If you put the RECURSIVE prefix on your SOLVE subroutine:
RECURSIVE subroutine solve(...)
...
end subroutine
you might be fine, even if multiple levels of other subprogram calls are interleaved. Without the prefix, your code is non-conforming (although you still might get correct results if the implementation uses a separate local context for each call).
Note however that if you have side effects (e.g. writing to module globals, variables in COMMON or local variables with the SAVE attribute) inside your SOLVE subprogram you still could be in trouble, since writes from different call sites could interfere with one another.
Regards
Reinhold
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This solved my problem(s): I had to declare explicitly ALL the subroutines of my solver as recursive, and I had to take care of a couple module variables as well.
Thanks Reinhold!
Olivier

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page