CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Reduce the memory usage in fortran (http://www.cfd-online.com/Forums/main/13908-reduce-memory-usage-fortran.html)

jinwon park August 3, 2007 09:35

Reduce the memory usage in fortran
 
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?


Tom August 3, 2007 09:59

Re: Reduce the memory usage in fortran
 
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.

jinwon park August 3, 2007 10:01

Re: Reduce the memory usage in fortran
 
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

andy August 3, 2007 10:26

Re: Reduce the memory usage in fortran
 
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?


jinwon park August 3, 2007 10:53

Re: Reduce the memory usage in fortran
 
5*150*150*4 That's usual array.

In main program, I have three above arrays.

Tom August 3, 2007 11:00

Re: Reduce the memory usage in fortran
 
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).

andy August 3, 2007 11:52

Re: Reduce the memory usage in fortran
 
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?


jinwon park August 3, 2007 21:15

Re: Reduce the memory usage in fortran
 
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?


andy August 4, 2007 03:48

Re: Reduce the memory usage in fortran
 
> 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).

jinwon park August 4, 2007 07:38

Re: Reduce the memory usage in fortran
 
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.

andy August 4, 2007 11:35

Re: Reduce the memory usage in fortran
 
> 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.


Harish August 4, 2007 12:33

Re: Reduce the memory usage in fortran
 
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.

jinwon park August 4, 2007 13:20

Re: Reduce the memory usage in fortran
 
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.


andy August 6, 2007 06:07

Re: Reduce the memory usage in fortran
 
> Yes. They are constant parameters with values known to the compiler.

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


jinwon park August 6, 2007 08:06

Re: Reduce the memory usage in fortran
 
What does automatic array mean? The dynamic array?

Could you show me a simple example?

andy August 6, 2007 08:55

Re: Reduce the memory usage in fortran
 
> 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.


jinwon park August 6, 2007 11:22

Re: Reduce the memory usage in fortran
 
Okay. Sorry about that

Lionel Larchevêque August 7, 2007 11:28

Re: Reduce the memory usage in fortran
 
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

jinwon park August 7, 2007 11:29

Re: Reduce the memory usage in fortran
 
Yes. I transformed the static array to the dynamic array. Then I solved this issue. Thanks anyway

Светлана March 5, 2014 01:08

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?


All times are GMT -4. The time now is 07:51.