Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error allocating an array

I have a subroutine which is called quite a lot during the Program run. I try to use as many allocatable arrays as possible, and the subroutine is called several times without any problem, but at some point, it terminates with:

malloc.c:3790: _int_malloc: Assertion `(unsigned long)(size) >= (unsigned long)(nb)' failed.

this happens at the beginning of the Subroutine when the first array is being allocated.

Using non-allocatable array instead, the subroutine is called several times more often but terminates again, now with:

 wait: 28674: Memory fault(coredump)

I assume that it terminates on calling, because I write out some values right after the declaration of the variables, without any computation.
The calling

do k=1, kreise
     write(*,*)k 

     call rundheit(n(k),kreis(k,1:n(k),3),kreis(k,1:n(k),2),outrnd)

end do

Where 'kreise' may have values of up to 1500. I printed out and checked the values of the parameters passed, before the call, in the subroutine and after the call.

Limiting 'kreise' does solve the problem, but limiting is not a practical solution. I need all the data to be evaluated. Not a fracture of it.

Some notes to my environment:
My program is a subroutine compiled by an FEM-Simulation-software using the Intel Fortran compiler. As far as I know I have no chance to alter the compiler options and I cannot compile my code on its own because it has to many dependencies on the subroutines deployed by the FEM-software.

I developed and run this exact subroutine on another, much smaller and simpler Simulation without any problems. The actual, ‘bigger’, simulation runs also without any problems as long as I don’t use this particular subroutine.(The difference is mostly the node density and thus the amount of data being considered during the computation) Other user-subroutine work without problems. All the subroutine do is fetch the results between some of the increments, do some analyses and write some reports without altering the Simulation.

I guess that the problem has something to do with the memory handling, something i have no idea of.

Thanks.

UPDATE
I compiled the subroutine using -check all and found the error occurs way before the blamed subroutine. Two arrays, one of them n(), are out of bound on several occasions, but the error gets somehow (more) critical while calling. The strange part is, that it is some iterations beyond the bound when the error occurs, for example: here both arrays have the size (1:72) and the calling breaks somewhere for k=135 to 267, (the lowest and highest values I found during some runs).

The problem is the integer Kreise, which value is set during a loop:

...
allocate(n(l))
allocate(pos(l))
...
do kreise = 1,l
   pos(kreise)=minvalX+(Kreise-1)*IncX
   if(pos(kreise).gt.maxvalX) exit
end do

Where kreise allways becomes l+1. Why?

NOTE: pos(kreise).gt.maxvalX should never be true. Becomming true isn't a problem, allthough it suggest that l was computed wrong (to big). This exit would then only save computation time later, by reducing the iterations of several loops.

like image 566
why.n0t Avatar asked Oct 21 '22 03:10

why.n0t


1 Answers

The program may be writing to memory that it shouldn't write to and corrupting the structures of the memory management of malloc that is used by Fortran allocate. I suggest using the Fortran option for run-time subscript checking. With ifort, try -check all or -check bounds.

like image 124
M. S. B. Avatar answered Nov 16 '22 10:11

M. S. B.