primesearch / Mlucas

Ⓜ️ Ernst Mayer's Mlucas and Mfactor programs for GIMPS
https://mersenneforum.org/mayer/README.html
GNU General Public License v3.0
8 stars 2 forks source link

FFT selection code #3

Closed xanthe-cat closed 8 months ago

xanthe-cat commented 8 months ago

As noted previously in #1 the default FFT selected for small exponents may be accurate but it misses the mark for Fermat exponents which have a limited range of possible FFTs that may be used. At Teal’s suggestion I’ve tested modifications to Mlucas.c, firstly at line 1261:

if(!fft_length || (!INTERACT && 8*fft_length > 9*kblocks && MODULUS_TYPE == MODULUS_TYPE_MERSENNE)) {

The added condition in the second clause ensures the 9 > 8 rule for selecting the next FFT doesn’t clobber Fermat exponents and retains the same behaviour for Mersennes. The more extensive modification at lines 1304 ff. or thereabouts prevent Mlucas running the self-test when Mlucas selects a wrong default FFT in spite of a user-supplied FFT.

    SETUP_FFT: /* CXC: addition by Teal D inserted at line 1308 to printf the preferred FFT length; also line 1310 if statement */
        /* Look for a best-FFT-radix-set entry in the .cfg file: */
        dum = get_preferred_fft_radix(kblocks);
        if(!dum) {  // Need to run a timing self-test at this FFT length before proceeding:
            sprintf(cbuf,"INFO: FFT length %d = %d K not found in the '%s' file.\n", n, kblocks, CONFIGFILE);
            fprintf(stderr,"%s", cbuf);
            if (!fft_length) return ERR_RUN_SELFTEST_FORLENGTH + (kblocks << 8);
        }
xanthe-cat commented 8 months ago

The nested if statement might better be written as

if (!fft_length || MODULUS_TYPE == MODULUS_TYPE_MERSENNE) return ERR_RUN_SELFTEST_FORLENGTH + (kblocks << 8);

as this leaves the handling of the Mersenne numbers completely unchanged.