问题
I have a Fortran program I wrote using Fotran 2003 and compiled using
Intel(R) Fortran Compiler XE for applications running on IA-32, Version 12.1.2.273 Build 20111128
after running my program for a long run ( it's a physical computation ) I have the out read:
Insufficient memory to allocate Fortran RTL message buffer, message
I guessed it has to do with memory leak in my program How can I find out where is the leak occurring and how to fix it?
回答1:
As the first answer indicates, your question is very general and not so amendable to a specific answer. Are you using pointers? Pointers are less safe than allocatables --- switch to allocatables if they will do the job.
A suggestion for debugging options for ifort: -O2 -stand f03 -assume realloc_lhs -check all -traceback -warn all -fstack-protector -assume protect_parens -implicitnone
回答2:
This is more of an extended comment than an answer ...
You have guessed that you have a memory leak, but you've not given us any information with which we can help you turn your guess into a diagnosis. In the absence of such information, some advice ...
a) memory leaks in Fortran programs occur in the same way they do in other programs: programmers forgetting (or neglecting) to deallocate variables when finished with; don't forget that with Fortran 2003 you can have allocatable scalars;
b) in long running scientific computations it's not unusual to find large arrays of outputs being built up iteratively, sometimes it's better to write these to disk during the computation than to wait until the end; you take a hit in I/O (well, mostly O) time but do economise on memory use;
c) there are a variety of tools available to help you spot memory leaks, including Intel Inspector and a variety of open-source programs;
d) you should understand quite well how the memory required by your program changes as it runs;
e) and sometimes, in this domain, the answer is just to buy more RAM.
回答3:
I suppose you already got you answer from the compiler: insufficient memory. At some point of your program you are trying to allocate a large memory.
You can compile your program with " -O0 -debug -traceback -check -ftrapuv " flags and run it again. You might use the intel debugger to go over the program line by line (I mean where you think the problem might be). With some luck you won't need to use other tools like valgrind.
Sometime, compiling with Gfortran will also help. Please note you need to use different compiler options to check the array bounds.
One last tip would be about using the "associate" construct. I personally had many problems using it. If you use it, remove it from your code and check things again.
来源:https://stackoverflow.com/questions/9751996/how-can-i-find-the-cause-for-a-memory-leak-in-fortran-2003-program