From: Jerry <lanceboyle@qwest.net>
Subject: Large arrays passed to arithmetic operators overflows GNAT stack
Date: Fri, 3 Dec 2010 22:32:59 -0800 (PST)
Date: 2010-12-03T22:32:59-08:00 [thread overview]
Message-ID: <da4fcb09-efa7-46d4-aece-e86b0dcf6674@v17g2000prc.googlegroups.com> (raw)
For what it's worth, passing large numerical arrays to the arithmetic
operators in GNAT can cause the stack to overflow (segfault) even when
the arrays are allocated from the heap. I suppose that indicates that
they are being copied rather than being passed by reference.
For example, on OS X which has a default stack size of 8192 KB, the
following program segfaults when N is greater than about 1_048_138
(about 8 MB per Long_Float array) but runs OK when it is somewhat less
than that number.
with
Ada.Numerics.Long_Real_Arrays;
use
Ada.Numerics.Long_Real_Arrays;
procedure array_test is
type Real_Vector_Access is access Real_Vector;
N : Integer := 1_048_130;
t_Ptr : Real_Vector_Access := new Real_Vector(0 .. N);
t : Real_Vector renames t_Ptr.all;
t_Diff_Ptr : Real_Vector_Access := new Real_Vector(0 .. N - 1);
t_Diff : Real_Vector renames t_Diff_Ptr.all;
begin
for i in t'range loop
t(i) := 1.0;
end loop;
t_Diff := t(1 .. N) - t(0 .. N - 1);
end array_test;
The quick fix (in my case) is to increase the stack size from the
shell:
ulimit -s 65532
or whatever is appropriate for your machine--65532 is the hard limit
set by OS X.
Another way to expand the stack without invoking shell commands, as
noted by Björn Persson on this thread
http://groups.google.com/group/comp.lang.ada/browse_thread/thread/ae395e5c11de7bc9/bda8d61bd3a66ee9?hl=en&q=Jerry+stack&lnk=nl&
is to call getrlimit and/or setrlimit from within the program, linking
to these POSIX C routines.
Another fix would be to write operator procedures that specifically
take pointers as arguments; that would possibly be the only fix for
arrays that still overflow the stack when it is maxed out.
As usual, taking the dumb-guy approach, this seems like an unnecessary
nuisance.
Jerry
next reply other threads:[~2010-12-04 6:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-04 6:32 Jerry [this message]
2010-12-04 9:19 ` Large arrays passed to arithmetic operators overflows GNAT stack Vinzent Hoefler
2010-12-04 13:27 ` Jeffrey Creem
2010-12-04 14:17 ` Peter C. Chapin
2010-12-05 1:22 ` Jerry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox