Re: Segmentation Fault when passing certain size array in a function



On 03/29/2011 09:26 AM, glen herrmannsfeldt wrote:
Uno <Uno@xxxxxxxxxxxxxxx> wrote:
(snip)

Do you have an example of a fortran recursion that would have unix
intervene, given that resources are wearing thin?

I'm in a position to test it on a 64-bit processor, with swap space.

program oops
call x(1)
end
recursive subroutine x(i)
if(mod(i,1000000).eq.0) print *,i
call x(i+1)
return
end

on my system, with the default stacksize (and 1000 instead of 1000000)
the last number is 39000.

-- glen

This is an almost perfect example of why C does not require as much stack space:
because of the pass-by-reference semantic of Fortran, every invocation of x
consumes stack space. The corresponding C program can be optimized into a
version that does not recurse at all and runs as long as permitted.

---------------------------------------------------
#include <stdio.h>

static void
x(int i)
{
if (!(i % 1000000))
fprintf(stderr, "i=%d\n", i);
x(i + 1);
}

int
main()
{
x(1);
}
--------------------------------------------------
Compiling with gcc-4.3 -O3 results in a program running for far longer than I'm
willing to wait.

Greetings, Thomas
.