Iwao Kimura on Wed, 28 Nov 2012 14:35:20 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: when pari_init() fail


Thank you for your prompt response/fix. The explanation in the
last paragraph is very clear.Â

The short code is written by some newbie of pari library programming.
It is not obvious for such people that what size of stack is enough forÂ
their daily use.Â

So I'd like to propose defining a macro, for example
#define DEFAULTSTACK 1000000
and its variants similar toÂ
the sample code would beÂ
pari_init(DEFAULTSTACK, 2);

The next point is what size of DEFAULTSTACK is enough for most users :)

Best regards.

On Wed, Nov 28, 2012 at 9:25 PM, Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr> wrote:
On Wed, Nov 28, 2012 at 05:37:28PM +0900, Iwao Kimura wrote:
> Hi all,
> The following short code is compiled normaly but it fails when invoked:
> /* zzpari.c */
> #include <pari/pari.h>
> int
> main (void)
> {
> Â pari_init(10000, 2);
> Â return 0;
> }
> $ gcc -o zzpari-dyn zzpari.c -O3 -mtune=native -g -Wall
> -fno-strict-aliasing -fomit-frame-pointer
> Â-I /home/iwao/include -L/home/iwao/lib -Wl,-rpath "/home/iwao/lib" -lpari
> -lgmp -lm
> $ ./zzpari-dyn
> Â *** Â bug in PARI/GP (Segmentation Fault), please report.
> Â *** Â Error in the PARI system. End of program.
> The code is 'git pull'ed today.
> I found the reason why this happen by some hours investigation,
> the first argument of pari_init() is too small.
> But I wonder this behavior is intended one or not.

No, it is a bug. In pari_init_opts(), the call to
initprimetable() happens too soon. It shoud at least
be after init_universal_constants() so that
err_e_STACK is defined.

With that change, one get:
 ***  the PARI stack overflows !
 current stack size: 10000 (0.010 Mbytes)
 [hint] you can increase GP stack with allocatemem()

 ***  Error in the PARI system. End of program.

Whether this one is intended or not is another story.
(This is due to commit 496549f714f3).
In practice, the prime table is computed at least up to
65309, which need about 40000 bytes of stack (on 64bit).