Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory leaks

Status
Not open for further replies.

Bosse7

Programmer
Aug 3, 2015
19
0
0
FR
I have now a program for thermodynamic calculations that runs well for most calculations but when it is used in large scale simulations (millions of calculations of equilibria with many components) it sometimes crashes due to lack of memory, i.e. there are some memory leaks.

I know this is probably an impossible questions but is there a way to find such leaks? The whole program is available as the opencalphad repository at github if anyone wants to test, running the parallel2 macro in an infinite loop shows the use of memory is gradually increasing.

The problem is more critical when the software is used by a code written in C++ via an isoC interface. Are there any known memory problems using this?

I use OpenMP for parallelization, any memory issues with that?

The rest is plain Fortran 08.

Thanks for any suggestions

 
1) Is the C++ part leak free? Leaks may be nothing to do with the Fortran section. Is it easy to write a Fortran program to call it so everything sits withing one languages - far easier to debug things that way.
2) Have you tried rebuilding and running it without openmp? It will take longer but does it still leak?
3) Is this on Windows or Linux?
3a) If Linux, try using valgrind.
3b) If windows, maybe try something like - bascially windows and free do not normally occur in the same sentence.
4) Does this only happen on one set of data or on all sets, no matter what the size?
 
Thanks, I will try these things. The problem is not really mine but from someone using my code. Normally I do not do millions of calculations, a few 1000 is enough to solve my problems but the problem seems independent of the type of data used.

I have seen a gradual increase in use of memory running the pure Fortran code but not as much as causing a crash for the time I waited. I have compiled and run the code on a Linux system so I can test it there.

Thanks again, I will forward the information to the one most concerned.

 
I have just tested valgrind, a fantastic software! I found a very subtle bug almost directly. But a bit complicated to understand the output.

But I have still severe memory leaks and I have a question. If a declate a pointer to a record TYPE in a subroutine and pass that pointer to another subroutine and inside that subroutine the record is allocated and later also used in the subroutine where the pointer was declared. In that subroutine I cannot deallocate it as it is a pointer. What happends when I nullify the pointer? Will the mamory used by the record be freed or will I just set the pointer to s "null" value? If so how can I free this memory? Do I have to allocate it before passing it the the other subroutine?

Originally I thought all memory used inside a subroutine would be freed when I leave the subroutine but I reallize that pointers are different. One can free the memory where the pointer is but the record it points to may be pointed to from other pointer variables.

The leaks are not associated with OpenMP and not with the C++ interface. It is inside the Fortran code.
 
Advice : do not allocate pointer variables. Allocate only allocatable variables. If you apply that carefully, then your memory leaks will disappear automatically.

Caution : I do not say that you cannot use pointer. You can of course but just to point to a memory zone already allocated.

François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top