0

我正在使用 perl 的 Crypt::Random 模块生成随机数,该模块依赖于 Math::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 MB?谢谢。

堆栈到 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');
4

1 回答 1

2

您不必使用 for allocatemem(),它被列为可以使用但不直接支持的功能之一,请参阅Math::Pari

相反,来自Math::Pari 中的 INITIALIZATION

加载 Math::Pari 时,它会检查变量 $Math::Pari::initmem 和 $Math::Pari::initprimes。他们指定了初始素数列表应该预先计算的数量,以及 PARI 计算的区域应该有多大(以字节为单位)。(这些值具有安全的默认值。)

由于在加载之前设置这些值需要一个 BEGIN 块,或者延迟加载(使用与需要),因此通过 Math::PariInit 设置它们可能更方便:

use Math::PariInit qw( primes=12000000 stack=1e8 );

请参阅Math::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 分钟内)。

通过这种方式,堆栈大小在编译时设置。请参阅第一个链接以动态更改它。

于 2016-10-18T21:23:08.110 回答