我使用perl的Crypt::随机模块生成随机数,该模块依赖于数学::Pari,这是Pari/GP的一个perl接口,当试图生成1.5M数字数字时,得到了这个错误:
C:\Users\Jlinne\Documents>perl -MCrypt::Random=makerandom_itv -E "say makerandom_itv(Lower => '10^1499999', Upper => '10^1500000')" > num_1500000.txt
PARI: *** the PARI stack overflows !
current stack size: 4.0 Mbytes
[hint] you can increase GP stack with allocatemem()
C:\Users\Ryan\Documents\Perl Scripts>perl scripts1.pl
"use" not allowed in expression at scripts1.pl line 6, at end of line
syntax error at scripts1.pl line 6, near "use Math::Pari
use Math::PariInit "
BEGIN not safe after errors--compilation aborted at scripts1.pl line 7.我的剧本:
#!/usr/bin/env perl
use warnings;
use strict;
use feature 'say';
use Math::Pari
use Math::PariInit qw( primes=12000000 stack=1e8 );
use Crypt::Random我已经猜到allocatemem()函数是个Math::Pari函数,但事实并非如此。有人知道使用脚本将GP堆栈大小更改为8.0兆字节吗?谢谢。
堆栈到1e+32的问题
C:\Users\Jlinne\Documents\Perl Scripts>perl scripts1.pl > BIGINT1500000.txt
PARI: *** the PARI stack overflows !
current stack size: 0.0 Mbytes
[hint] you can increase GP stack with allocatemem()
Compilation failed in require at C:/Strawberry/perl/site/lib/Math/PariInit.pm line 26.
BEGIN failed--compilation aborted at scripts1.pl line 6.剧本:
use warnings 'all';
use strict;
use feature 'say';
# use Math::Pari;
use Math::PariInit qw( stack=1e32 );
use Crypt::Random qw(makerandom_itv);
say makerandom_itv(Lower => '10^1499999', Upper => '10^1500000');发布于 2016-10-18 21:23:08
您不必访问allocatemem(),它被列为可以使用但不受直接支持的函数之一,请参阅这是数学中的::Pari。
相反,来自数学初始化::Pari
加载Math::Pari时,它将检查变量$Math::Pari::initmem和$Math::Pari::initprimes。它们指定了应该预先计算的初始素数列表的数目,以及PARI计算的范围(以字节为单位)。(这些值具有安全的默认值。) 由于在加载之前设置这些值需要一个BEGIN块,或者延迟加载(使用和要求),因此通过Math::PariInit设置它们可能更方便: 使用数学::PariInit( primes=12000000 stack=1e8 );
请参阅数学::PariInit的(简称)页面。
一个完整的例子
use warnings 'all';
use strict;
use feature 'say';
# use Math::Pari;
use Math::PariInit qw( stack=1e8 );
use Crypt::Random qw(makerandom_itv);
say makerandom_itv(Lower => '10^1499999', Upper => '10^1500000')";运行script.pl > BIG_num.txt将生成一个1.5Mb文件(在11分钟内)。
这样,在编译时就可以设置堆栈大小。请参见动态更改它的第一个链接。
https://stackoverflow.com/questions/40118155
复制相似问题