CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

Reduce the memory usage in fortran

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   August 3, 2007, 09:35
Default Reduce the memory usage in fortran
  #1
jinwon park
Guest
 
Posts: n/a
I am solving the compressible flow coupled with level set method in 2D.

Now, the maximum size of arrays I can is 145*145 but it's not enough to solve something.
: I am just using static array, not any dynamic array
: The solution array is 4-dimensional array
: The error messege is below

Segmentation fault

I really want to solve problem with the grid 500*500 at least.

How can I increase the grid size in fortran?

  Reply With Quote

Old   August 3, 2007, 09:59
Default Re: Reduce the memory usage in fortran
  #2
Tom
Guest
 
Posts: n/a
Fortrans probably not the problem. The seg fault is either because you need to increase the floating stack size (ulimit -s unlimited) or more likely there's an array addressing error in your code - 4*145*145 = 657Kb in double precision which is not a large amount of memory.
  Reply With Quote

Old   August 3, 2007, 10:01
Default Re: Reduce the memory usage in fortran
  #3
jinwon park
Guest
 
Posts: n/a
Yes. I am using the statement, 'IMPLICIT DOUBLE PRECISION(a-h,o-z)' to define all variables.

To avoid the problem you mentioned, please let me know how to do by myself.

Thanks for your reply
  Reply With Quote

Old   August 3, 2007, 10:26
Default Re: Reduce the memory usage in fortran
  #4
andy
Guest
 
Posts: n/a
What is the declared size of your 4 dimensional array?

500*500*500*500*8 = too many bytes of memory

Another common problem is declaring an array on the stack and not on the heap. Are your array dimensions variables or constants?

  Reply With Quote

Old   August 3, 2007, 10:53
Default Re: Reduce the memory usage in fortran
  #5
jinwon park
Guest
 
Posts: n/a
5*150*150*4 That's usual array.

In main program, I have three above arrays.
  Reply With Quote

Old   August 3, 2007, 11:00
Default Re: Reduce the memory usage in fortran
  #6
Tom
Guest
 
Posts: n/a
Look at the manual for your fortran compiler - and switch on all the debug options for array bounds etc (eg. "-g -check all -trace" for the intel compiler).
  Reply With Quote

Old   August 3, 2007, 11:52
Default Re: Reduce the memory usage in fortran
  #7
andy
Guest
 
Posts: n/a
5*150*150*5*8*3 = 10 800 000 bytes

This is the sort of size that is too big for the stack but fine for the heap assuming you have 100s of MBytes of free memory.

How have you declared these arrays?

  Reply With Quote

Old   August 3, 2007, 21:15
Default Re: Reduce the memory usage in fortran
  #8
jinwon park
Guest
 
Posts: n/a
I just used the static array like

DIMENSION u0(0:5,0:nx+1,0:ny+1,4)....

I defined all arrays in code like above. You meant if I used a dynamic array, I can avoid such a problem. Is that right?

  Reply With Quote

Old   August 4, 2007, 03:48
Default Re: Reduce the memory usage in fortran
  #9
andy
Guest
 
Posts: n/a
> You meant if I used a dynamic array, I can avoid such a problem. Is that
: right?

No. The potential problem concerns automatic arrays being allocated on the stack and not the heap with some compilers.

If your array is local to the subroutine (i.e. not in the argument list) and the values of nx and ny are not constant but variables then some compilers will allocate this array automatically on the stack when the subroutine is called. Depending on your environment, the size of the stack may be small. The solution is to increase the size of your stack (messy), pass a flag to the compiler instructing it to put such arrays on the heap (messy) or not to declare potentially large arrays as automatic (the best solution).
  Reply With Quote

Old   August 4, 2007, 07:38
Default Re: Reduce the memory usage in fortran
  #10
jinwon park
Guest
 
Posts: n/a
Actually, I am not familiar with the area you metioned, heap, stak or something else.

Nx, Ny are constant over time steps. Some arrays are local but the other are global.

I don't know how to do followings in fortran

"The solution is to increase the size of your stack (messy), pass a flag to the compiler instructing it to put such arrays on the heap (messy) or not to declare potentially large arrays as automatic (the best solution)"

Could you show me an example or good reference for it?

Thanks in advance.
  Reply With Quote

Old   August 4, 2007, 11:35
Default Re: Reduce the memory usage in fortran
  #11
andy
Guest
 
Posts: n/a
> Nx, Ny are constant over time steps

They are either constant parameters with values known to the compiler or they are variables with values only known at runtime.

> Could you show me an example or good reference for it?

The manual for your compiler will tell you how automatic arrays are handled in your particular case. There are many books and tutorials on Fortran including a reasonable number freely available on the web.

  Reply With Quote

Old   August 4, 2007, 12:33
Default Re: Reduce the memory usage in fortran
  #12
Harish
Guest
 
Posts: n/a
A colleague of mine once had this problem.The solution depends on the compiler you are using.If it is g77 then you should be able to find it in the documentation.For commerical compilers check the manual or check the compiler settings on how to use it.Commerical compiler manuals may not be available online.Hope this helps.
  Reply With Quote

Old   August 4, 2007, 13:20
Default Re: Reduce the memory usage in fortran
  #13
jinwon park
Guest
 
Posts: n/a
Yes. They are constant parameters with values known to the compiler.

I am using intel fortran v.10 in linux. It's same as in the previous intel fortran versions.

  Reply With Quote

Old   August 6, 2007, 06:07
Default Re: Reduce the memory usage in fortran
  #14
andy
Guest
 
Posts: n/a
> Yes. They are constant parameters with values known to the compiler.

In which case they are not automatic arrays and your problem lies elsewhere.

  Reply With Quote

Old   August 6, 2007, 08:06
Default Re: Reduce the memory usage in fortran
  #15
jinwon park
Guest
 
Posts: n/a
What does automatic array mean? The dynamic array?

Could you show me a simple example?
  Reply With Quote

Old   August 6, 2007, 08:55
Default Re: Reduce the memory usage in fortran
  #16
andy
Guest
 
Posts: n/a
> What does automatic array mean? The dynamic array?
: Could you show me a simple example?

I do not mind helping you to understand your problem when it is not obvious but you can look in your fortran manual or type "fortran automatic array" into google to answer this type of question.

  Reply With Quote

Old   August 6, 2007, 11:22
Default Re: Reduce the memory usage in fortran
  #17
jinwon park
Guest
 
Posts: n/a
Okay. Sorry about that
  Reply With Quote

Old   August 7, 2007, 11:28
Default Re: Reduce the memory usage in fortran
  #18
Lionel Larchevêque
Guest
 
Posts: n/a
Hi,

As suggested previously, try ulimit -s unlimited to increase the size of the stack (assuming you are using a unix/linux OS). It helps me a lot of time. Otherwise transform your static arrays into dynamics ones. It is a rather simple operation.

Regards,

Lionel
  Reply With Quote

Old   August 7, 2007, 11:29
Default Re: Reduce the memory usage in fortran
  #19
jinwon park
Guest
 
Posts: n/a
Yes. I transformed the static array to the dynamic array. Then I solved this issue. Thanks anyway
  Reply With Quote

Old   March 5, 2014, 01:08
Default
  #20
Member
 
Join Date: Oct 2013
Posts: 30
Rep Power: 3
Светлана is on a distinguished road
Presumably dynamic are the allocatables ("real, allocatable :: array(:, :, : ) allocate(array(k,l,m))" for example) and static ones are not allocatable ("real :: array(k,l,m)" for example). How are dynamic arrays more useful for memory usage? Is that just to please the compiler to convince it to keep them in heap instead of stack, or is it something else?
Светлана is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 18:56
Fluent Parallel Memory Usage David Christopher FLUENT 1 March 3, 2011 03:20
How to optimize the memory usage when using FEM vasilis Main CFD Forum 11 August 24, 2009 23:57
memory ms visual fortran 6 vadim Main CFD Forum 0 December 20, 2008 14:01
memory calculation of variables in FORTRAN codes John Main CFD Forum 1 April 8, 2002 14:13


All times are GMT -4. The time now is 22:55.