LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-19-2009, 11:01 AM   #1
otoomet
Member
 
Registered: Oct 2004
Location: Tartu, Ċrhus,Nürnberg, Europe
Distribution: Debian, Ubuntu, Puppy
Posts: 588

Rep: Reputation: 45
local dynamically allocated array in fortran


Hi,

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.

Thanks in advance,
Ott
 
Old 10-19-2009, 02:12 PM   #2
mostlyharmless
Senior Member
 
Registered: Jan 2008
Distribution: Slackware -current (multilib) with kernel 3.15.5
Posts: 1,497
Blog Entries: 12

Rep: Reputation: 155Reputation: 155
Not in *real* (i.e '66) FORTRAN Seriously, they made this possible in Fortran 90 , sort of in '77, see the following:

http://www.ibms.sinica.edu.tw/~jon/dyn_mem.shtml


gotten from google "fortran 90 dynamic memeory allocation"

Last edited by mostlyharmless; 10-19-2009 at 02:22 PM.
 
Old 10-19-2009, 02:27 PM   #3
otoomet
Member
 
Registered: Oct 2004
Location: Tartu, Ċrhus,Nürnberg, Europe
Distribution: Debian, Ubuntu, Puppy
Posts: 588

Original Poster
Rep: Reputation: 45
Thanks.

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

Best,
Ott
 
Old 10-19-2009, 04:30 PM   #4
mostlyharmless
Senior Member
 
Registered: Jan 2008
Distribution: Slackware -current (multilib) with kernel 3.15.5
Posts: 1,497
Blog Entries: 12

Rep: Reputation: 155Reputation: 155
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...
 
Old 10-20-2009, 02:20 AM   #5
otoomet
Member
 
Registered: Oct 2004
Location: Tartu, Ċrhus,Nürnberg, Europe
Distribution: Debian, Ubuntu, Puppy
Posts: 588

Original Poster
Rep: Reputation: 45
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.

But thanks,
Ott
 
Old 10-21-2009, 08:28 AM   #6
mostlyharmless
Senior Member
 
Registered: Jan 2008
Distribution: Slackware -current (multilib) with kernel 3.15.5
Posts: 1,497
Blog Entries: 12

Rep: Reputation: 155Reputation: 155
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send the dynamically allocated two dimensional character array through C++ UDP kbarani Linux - Software 3 05-04-2009 11:41 PM
problem with RTC minor and major allocated dynamically semi-hor Linux - Kernel 0 06-12-2008 08:48 AM
In C, using qsort for dynamically allocated array ntmsz Programming 7 08-23-2005 10:33 AM
Need help: Seg fault, Memcpy, and dynamically allocated arrays benobi Programming 3 06-09-2005 10:58 PM
how to create device node for dynamically allocated major number appas Programming 5 11-01-2004 09:37 AM


All times are GMT -5. The time now is 02:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration