|
[Sponsors] |
August 3, 2007, 10:35 |
Reduce the memory usage in fortran
|
#1 |
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? |
|
August 3, 2007, 10:59 |
Re: Reduce the memory usage in fortran
|
#2 |
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.
|
|
August 3, 2007, 11:01 |
Re: Reduce the memory usage in fortran
|
#3 |
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 |
|
August 3, 2007, 11:26 |
Re: Reduce the memory usage in fortran
|
#4 |
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? |
|
August 3, 2007, 11:53 |
Re: Reduce the memory usage in fortran
|
#5 |
Guest
Posts: n/a
|
5*150*150*4 That's usual array.
In main program, I have three above arrays. |
|
August 3, 2007, 12:00 |
Re: Reduce the memory usage in fortran
|
#6 |
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).
|
|
August 3, 2007, 12:52 |
Re: Reduce the memory usage in fortran
|
#7 |
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? |
|
August 3, 2007, 22:15 |
Re: Reduce the memory usage in fortran
|
#8 |
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? |
|
August 4, 2007, 04:48 |
Re: Reduce the memory usage in fortran
|
#9 |
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). |
|
August 4, 2007, 08:38 |
Re: Reduce the memory usage in fortran
|
#10 |
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. |
|
August 4, 2007, 12:35 |
Re: Reduce the memory usage in fortran
|
#11 |
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. |
|
August 4, 2007, 13:33 |
Re: Reduce the memory usage in fortran
|
#12 |
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.
|
|
August 4, 2007, 14:20 |
Re: Reduce the memory usage in fortran
|
#13 |
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. |
|
August 6, 2007, 07:07 |
Re: Reduce the memory usage in fortran
|
#14 |
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. |
|
August 6, 2007, 09:06 |
Re: Reduce the memory usage in fortran
|
#15 |
Guest
Posts: n/a
|
What does automatic array mean? The dynamic array?
Could you show me a simple example? |
|
August 6, 2007, 09:55 |
Re: Reduce the memory usage in fortran
|
#16 |
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. |
|
August 6, 2007, 12:22 |
Re: Reduce the memory usage in fortran
|
#17 |
Guest
Posts: n/a
|
Okay. Sorry about that
|
|
August 7, 2007, 12:28 |
Re: Reduce the memory usage in fortran
|
#18 |
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 |
|
August 7, 2007, 12:29 |
Re: Reduce the memory usage in fortran
|
#19 |
Guest
Posts: n/a
|
Yes. I transformed the static array to the dynamic array. Then I solved this issue. Thanks anyway
|
|
March 5, 2014, 01:08 |
|
#20 |
Senior Member
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15 |
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?
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CFX11 + Fortran compiler ? | Mohan | CFX | 20 | March 30, 2011 19: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 25, 2009 00: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 15:13 |