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.
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.