Skip to content

Commit 4db49dc

Browse files
committed
Don't allow testing non-prime exponents. They sometimes raise excessive roundoff errors.
1 parent 46386d0 commit 4db49dc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Task.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Worktodo.h"
99
#include "Saver.h"
1010
#include "version.h"
11+
#include "Primes.h"
1112
#include "Proof.h"
1213
#include "log.h"
1314
#include "timeutil.h"
@@ -211,6 +212,20 @@ void Task::execute(GpuCommon shared, Queue *q, u32 instance) {
211212

212213
assert(exponent);
213214

215+
// Testing exponent 140000001 using FFT 512:15:512 fails with severe round off errors.
216+
// I'm guessing this is because bot the exponent and FFT size are divisible by 3.
217+
// Here we make sure the exponent is prime. If not we do not raise an error because it
218+
// is very common to use command line argument "-prp some-random-exponent" to get a quick
219+
// timing. Instead, we output a warning and test a smaller prime exponent.
220+
{
221+
Primes primes;
222+
if (!primes.isPrime(exponent)) {
223+
u32 new_exponent = primes.prevPrime(exponent);
224+
log("Warning: Exponent %u is not prime. Using exponent %u instead.\n", exponent, new_exponent);
225+
exponent = new_exponent;
226+
}
227+
}
228+
214229
LogContext pushContext(std::to_string(exponent));
215230

216231
FFTConfig fft = FFTConfig::bestFit(*shared.args, exponent, shared.args->fftSpec);

0 commit comments

Comments
 (0)