Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Memory leak using forall statement

s_haeri
Beginner
816 Views
Hi,

I am working ona Fortran95 CFD code and when I use FORALL statements with pure functionsit causes memory leaks,following line is an example ofthe code that causes the problem:

FORALL(L=nlic(nb):nli(nb)) phi(li(L),ndphidtime) = interpp3n_r0(phi(li(L),phikey(phase,sphi,1:3)),r1,dt(1:2)),

where nlic, nli, li and phikey are integer arrays, r1 is a real, phi(:,:) and dtare real arraysand interpp3n_r0 is a pure function. It seems the compiler allocates temporary arrays but neverfrees them. The code works just fine when I change the Forall to DO loops.

I am using Intel FORTRAN compiler 11.1 integrated into the VS 2008 professional.

I amnew to the forumand sorry if the issue is already discussed,

Thank you


0 Kudos
8 Replies
Steven_L_Intel1
Employee
816 Views
Welcome to the forum.

We would need to see a small(if possible) but complete example in order to investigate this. What sort of memory leak are you referring to?
0 Kudos
s_haeri
Beginner
816 Views

Thank you for the reply. I've attached two files: test.f90 is the main code and funcs.f90 contains two functions that are called by the main program.In the following do loop (line 22 of test.f90) the size of the program starts to grow after each call to FORALL.

Do i = 1,10

FORALL(L=1:mil) phi(li(L),3) = interpp3n_r0(phi(li(L),range),r1,dx(1:2))

ENDDO

This is exactly what happens in the code and the program size grows until the machine runs out of memory.

Thank you

sina

0 Kudos
Steven_L_Intel1
Employee
816 Views
I can't reproduce the problem with either 11.1.067 (Update 7) or 12.0. I don't see anything in this code that could cause memory to expand - there is no dynamic memory used. Which exact compiler version are you using?
0 Kudos
s_haeri
Beginner
816 Views
I am using 11.1.067, with vs2008. Exactly, initially (before the do loop) the program uses about 18MB of memory which should remain constant during the lifetime of the program.in each execution of the do loop the size of the program increases by the same amount.and after 10 iteration which is nothing more thansome calculations andassignments, it expands to around 180MB. and this happens when the ''range'' is not contiguous, for example if you set range(3) = (/1,2,3/) the program size remains constant at 18MB. but for example with range(3) = (/1,2,4/) the size increases.
0 Kudos
s_haeri
Beginner
816 Views
I am also building the program in debug mode (haven't check the release mode yet) and using heap-array compiler option (set to 0)

Thanks
0 Kudos
Steven_L_Intel1
Employee
816 Views
Ah, yes, I can see the problem with heap-arrays, though for me the program does not run out of memory (it does leak it.) Can you do without heap-arrays in your actual application? Would you consider not using FORALL for now?
0 Kudos
s_haeri
Beginner
816 Views

yes but if you makethe arraylarger or run it longer (i = 1,1000 for example) it will eventually crash. anyway I can't change the heap-arrays as there are lots of large arrays passed to subroutines and I get stack over flows, however I'm considering changing foralls to do loops as I am also having problems with pointer assignmentsand foralls. I probably convert foralls to do loops, there arelots of them though.

Thank you for the help

0 Kudos
Steven_L_Intel1
Employee
816 Views
Ok. A lot of people misunderstand FORALL - it is a form of array assignment, not a loop. You might consider DO CONCURRENT, new in version 12. This is FORALL the way it should have been specified.
0 Kudos
Reply