Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Memory leaks

Memory leaks

Memory leaks

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

RE: Memory leaks

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 http://winleak.sourceforge.net/ - 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?

RE: Memory leaks

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.

RE: Memory leaks

Since you're using Linux, have a look at http://elinux.org/Memory_Debuggers

There are quite a few debuggers there. To eliminate whether it is OpenMP or not, just run with OMP_NUM_THREADS=1

RE: Memory leaks

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.

RE: Memory leaks

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close