mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Software (https://www.mersenneforum.org/forumdisplay.php?f=10)
-   -   Pminus1 - Bug report and feature request (https://www.mersenneforum.org/showthread.php?t=22776)

axn 2017-12-10 12:30

Pminus1 - Bug report and feature request
 
The following is a bug in calc_exp
[CODE] if (len >= 50) {
giant x;
calc_exp (pm1data, k, b, n, c, g, B1, p, lower, lower + (len >> 1));
x = allocgiant (len);
calc_exp (pm1data, k, b, n, c, x, B1, p, lower + (len >> 1), upper);
mulg (x, g);
free (x);
return;
}

[B]itog (2*n, g);[/B]

for ( ; *p <= B1 && (unsigned long) g->sign < len; *p = sieve (pm1data->sieve_info)) {
uint64_t val, max;
val = *p;
max = B1 / *p;
while (val <= max) val *= *p;
ullmulg (val, g);
}[/CODE]
g is initialized to 2*n. The problem is that, this is done for every (recursive) tail call of calc_exp, instead of just the first one, so we end up with B/50 (or more) multiples of 2*n. This just makes stage 0 longer than needed (probably on the order of 5% or so).
What is needed:
[CODE]if(lower==0)
itog (2*n, g);
else
setone(g);
[/CODE]

[B]Now, the feature request:[/B]
Make stage 0 bigger. Right now it is a paltry 1M ([c]stage_0_limit = (pm1data.B > 1000000) ? 1000000 : pm1data.B;[/c]), which is probably fine for regular GIMPS work, but at the mid-to-low end, we routinely deal with much bigger B1
So instead, make it as big as possible (100m is not too bad, since we're looking at < 20MB memory use). If calc_exp takes lot of time to do the actual calculation, make it as big as can be reasonably done by a modern processor in, say 60 seconds.

Prime95 2017-12-10 17:18

Dang, the code used to be right and a bug fix broke it. I'll work up a re-fix.

Interestingly, I also saw the stage 0 optimization opportunity a month ago. The only hard part of implementing this is that it breaks existing save files that paused during stage 0. Not insurmountable, I need to bump the version number and either make calc_exp support both formulas based on the save file version number OR simply toss old save files that are in stage 0. I'm feeling lazy today -- tossing sounds better.

Prime95 2017-12-11 22:37

[QUOTE=axn;473623][B]Now, the feature request:[/B]Make stage 0 bigger.[/QUOTE]

I've got this coded, raising B1 to 13.3M (about 20M bits). Do you think it should be more? I replaced giants code with GMP code so calc_exp should be faster. Do you want a 29.4b7 to try it out? If so, Windows or Linux.

As I noted earlier, resuming from an older P-1 save file in stage 1 will restart the calculation.

axn 2020-05-18 13:54

[QUOTE=Prime95;473769]I've got this coded, raising B1 to 13.3M (about 20M bits). Do you think it should be more? I replaced giants code with GMP code so calc_exp should be faster. Do you want a 29.4b7 to try it out? If so, Windows or Linux.[/QUOTE]

I am currently doing some low range P-1 with B1=30M. It would be really cool if this limit can be further bumped up (to about 100Mbits).

axn 2020-05-25 10:20

[QUOTE=axn;545718]I am currently doing some low range P-1 with B1=30M. It would be really cool if this limit can be further bumped up (to about 100Mbits).[/QUOTE]

:bump:

George, is this something that you can spend time on?

kruoli 2020-05-25 19:23

Since I'm also doing some P-1 with big B1 (and B2), I would be interested in this, too (following axn's reasoning). Can somebody elaborate what stage 0 is? Googling for it only lead me to some biological stuff... :mike:

@George: If it helps, I'd take a 29.4b7 for testing, Windows.

Prime95 2020-05-25 22:28

[QUOTE=axn;546389]:bump:

George, is this something that you can spend time on?[/QUOTE]



I might can look at it in June. Nag me later. Right now I cannot build a Windows version. With the new laptop comes an upgrade from MSVC 2005 to MSVC 2019.

If the change requires a change to the save file format that could complicate matters.

axn 2020-05-26 03:31

[QUOTE=Prime95;546434]I might can look at it in June. Nag me later.[/QUOTE]

Sure, will do.

FTR, I am on linux.

axn 2020-05-26 03:43

[QUOTE=kruoli;546418]Can somebody elaborate what stage 0 is?[/QUOTE]

Stage 1 of P-1 is implemented in two steps, a fast(er) Stage 0 and a slow(er) regular Stage 1.

The current stage 0 limit is about 13.3M. If your B1 is < 13.3M, you already run the entire Stage 1 using the faster stage 0 logic. If your B1 > 13.3M, then all the small primes up to 13.3M is handled using stage 0 logic and everything above 13.3M is handled using the slower stage 1 logic. One side effect of this is that, the % completed will jump by different amounts during status updates. Initially, it will be advancing x% every status update, and then suddenly it will drop to x/1.5 % after stage 0 is done.

kruoli 2020-05-26 22:19

May we add an entry to the Wiki for future interests? Or any kind of google-searchability?

kruoli 2020-05-26 22:20

[QUOTE=axn;546457]I am on linux.[/QUOTE]

If that's a barrier, I can run it on Linux, too. I'm on dual-boot on nearly all machines.


All times are UTC. The time now is 07:49.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.