• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Alternative to SAVE and DATA in Fortran?

Born2bwire

Diamond Member
I've got a FORTRAN code that is an iterative matrix solver that I am calling from C++. It is set up as a set of subroutines that I run each iteration. After the subroutines return, they store information in a passed in array that tells me what I need to perform on the data.

So basically, I run the subroutine, it returns and I find that I need to provide a matrix vector product or something like that, I write the new info into the workspace array and pass it back into the subroutine the next iteration.

I need to make this program thread safe so that I can parallelize my code. However, the code makes use of the SAVE statement to keep a number of variables persisting in data. Presumably this is so that the data is at hand when I rerun the subroutine in the next iteration. But with multiple threads running at the same time, it seems that the various threads are writing over and reading each other's saved data.

Is there an alternative to using the SAVE statement so that the subroutine will be thread safe?

Perhaps the obvious solution would be to store the desired data into the workspace that is returned at the conclusion of the subroutine. But since I have worked little with FORTRAN I wanted to ask to see if there were any simpler or easier solutions. Not to mention I may not be so lucky with future legacy code to have a handy workspace to write the data into.
 
Setup a second array to hold variables that are being captured by SAVE.

The controller of the thread can then make the determination on what to do with those pieces.

There may be other solutions; you may have a hard time finding out.
So few FORTRAN programmers that are current, exist.
My skills are 20+ years old in that department
 
Setup a second array to hold variables that are being captured by SAVE.

The controller of the thread can then make the determination on what to do with those pieces.

There may be other solutions; you may have a hard time finding out.
So few FORTRAN programmers that are current, exist.
My skills are 20+ years old in that department

That is what I am intending to do. I already have a large array as a workspace that is passed in and out of the subroutines. I can just increase the workspace and use it to store the saved variables. The problem is that I may not always be so lucky in the future. I may have a subroutine that uses SAVE that does not pass in and out an array. Of course I can modify it to do so, but then I would have to modify the parent routines that call the subroutine and it can snowball quickly from there.

But like you, I can't think of an alternative other than passing the data back up.
 
Back
Top