ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I (my friend) have a fortran program with the code along the following lines:
Code:
SUBROUTINE NY
REAL, DIMENSION(4000,4000) :: a, b, c
...
RETURN
END SUBROUTINE PARAMETERS
The problem is that the huge matrices are retained in memory even after the subroutine ends. Is there an easy way to declare the arrays in a sort of dynamic way, like they were in the following C example?
Code:
void ny(void) {
double a[4000,4000];
...
}
I mean in the C example the memory is released as soon ny() exits.
But isn't there any simpler way? The problem is not so much not knowing the size while initializing the matrices, but the fact that the memory is not freed while exiting from the subroutine. It looks like the matrices were defined as "static double a[4000,4000]" in C. I'd like to have them temporary as simply "double a[4000,4000]".
Simpler way? I didn't think the example was all that bad, just a bit "C-ish". I don't know if there's any other way, other than coding everything in C, or making a C library subroutine for dynamic matrices, but those are both more complicated ways. Maybe in the next version of Fortran...
Hmmm... It works in a sense that the variable values are not retained between successive function calls. However, it seems like the memory is not freed after return from the subroutine. The memory usage jumps every time I call a new subroutine, although I now allocate the memory in the way as suggested in the example.
Maybe that's a compiler implementation issue; I don't know enough about the Fortran 90 specs to say. If you have more than one compiler you can check it with, it'd be worth a try.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.