Re: Segmentation Fault when passing certain size array in a function
- From: Thomas Jahns <jahns@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Mar 2011 13:33:15 +0200
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
.
- Follow-Ups:
- Re: Segmentation Fault when passing certain size array in a function
- From: glen herrmannsfeldt
- Re: Segmentation Fault when passing certain size array in a function
- From: Tobias Burnus
- Re: Segmentation Fault when passing certain size array in a function
- References:
- Segmentation Fault when passing certain size array in a function
- From: Eric
- Re: Segmentation Fault when passing certain size array in a function
- From: Ken Fairfield
- Re: Segmentation Fault when passing certain size array in a function
- From: Eric
- Re: Segmentation Fault when passing certain size array in a function
- From: Richard Maine
- Re: Segmentation Fault when passing certain size array in a function
- From: glen herrmannsfeldt
- Re: Segmentation Fault when passing certain size array in a function
- From: Richard Maine
- Re: Segmentation Fault when passing certain size array in a function
- From: glen herrmannsfeldt
- Re: Segmentation Fault when passing certain size array in a function
- From: Uno
- Re: Segmentation Fault when passing certain size array in a function
- From: glen herrmannsfeldt
- Segmentation Fault when passing certain size array in a function
- Prev by Date: Re: Question about enumerations
- Next by Date: Re: Segmentation Fault when passing certain size array in a function
- Previous by thread: Re: Segmentation Fault when passing certain size array in a function
- Next by thread: Re: Segmentation Fault when passing certain size array in a function
- Index(es):
Relevant Pages
|