mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2017-12-10, 12:30   #1
axn
 
axn's Avatar
 
Jun 2003

17·281 Posts
Default 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;
	}

	itog (2*n, g);

	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);
	}
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);
Now, the feature request:
Make stage 0 bigger. Right now it is a paltry 1M (stage_0_limit = (pm1data.B > 1000000) ? 1000000 : pm1data.B;), 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.

Last fiddled with by axn on 2017-12-10 at 12:31
axn is offline   Reply With Quote
Old 2017-12-10, 17:18   #2
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

2·3·1,193 Posts
Default

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 is online now   Reply With Quote
Old 2017-12-11, 22:37   #3
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

2×3×1,193 Posts
Default

Quote:
Originally Posted by axn View Post
Now, the feature request:Make stage 0 bigger.
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.
Prime95 is online now   Reply With Quote
Old 2020-05-18, 13:54   #4
axn
 
axn's Avatar
 
Jun 2003

12A916 Posts
Default

Quote:
Originally Posted by Prime95 View Post
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.
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 is offline   Reply With Quote
Old 2020-05-25, 10:20   #5
axn
 
axn's Avatar
 
Jun 2003

17·281 Posts
Default

Quote:
Originally Posted by axn View Post
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).


George, is this something that you can spend time on?
axn is offline   Reply With Quote
Old 2020-05-25, 19:23   #6
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

367 Posts
Default

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...

@George: If it helps, I'd take a 29.4b7 for testing, Windows.
kruoli is offline   Reply With Quote
Old 2020-05-25, 22:28   #7
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

2×3×1,193 Posts
Default

Quote:
Originally Posted by axn View Post


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


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.
Prime95 is online now   Reply With Quote
Old 2020-05-26, 03:31   #8
axn
 
axn's Avatar
 
Jun 2003

112518 Posts
Default

Quote:
Originally Posted by Prime95 View Post
I might can look at it in June. Nag me later.
Sure, will do.

FTR, I am on linux.
axn is offline   Reply With Quote
Old 2020-05-26, 03:43   #9
axn
 
axn's Avatar
 
Jun 2003

17·281 Posts
Default

Quote:
Originally Posted by kruoli View Post
Can somebody elaborate what stage 0 is?
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.
axn is offline   Reply With Quote
Old 2020-05-26, 22:19   #10
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

367 Posts
Default

May we add an entry to the Wiki for future interests? Or any kind of google-searchability?
kruoli is offline   Reply With Quote
Old 2020-05-26, 22:20   #11
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

367 Posts
Default

Quote:
Originally Posted by axn View Post
I am on linux.
If that's a barrier, I can run it on Linux, too. I'm on dual-boot on nearly all machines.

Last fiddled with by kruoli on 2020-05-26 at 22:21 Reason: merely \neq nearly
kruoli is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
feature request P-1 tha Software 4 2014-02-23 21:29
Feature request TheMawn PrimeNet 3 2013-06-17 02:32
Feature request JuanTutors Software 22 2013-03-11 19:23
v5.0 Feature Request Bent PrimeNet 2 2008-12-07 23:22
feature request tha PrimeNet 10 2003-12-12 15:37

All times are UTC. The time now is 21:29.

Thu Nov 26 21:29:06 UTC 2020 up 77 days, 18:40, 4 users, load averages: 1.91, 1.83, 1.56

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

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.