Skip to content

Commit 1a68c71

Browse files
authored
Merge pull request #55 from ixfd64/params-macros
convert hard-coded values to macros
2 parents 38e43c0 + 05f79c8 commit 1a68c71

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

Changelog-mfakto.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ other changes:
5252
- requested by James Heinrich: results are no longer saved to deprecated
5353
results.txt by default (thanks to NStorm)
5454
- please use results.json.txt for submissions
55-
- set LegacyResultsTxt=1 in mfaktc.ini to restore old behavior and re-enable
55+
- set LegacyResultsTxt=1 in mfakto.ini to restore old behavior and re-enable
5656
logging to results.txt
5757
- merged in James Heinrich's changes to mfaktc.ini and re-organized mfakto.ini
5858
to be more user-friendly

src/mfaktc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ along with mfaktc (mfakto). If not, see <http://www.gnu.org/licenses/>.
3535
#include "compatibility.h"
3636
#include "sieve.h"
3737
#include "read_config.h"
38+
#include "params.h"
3839
#include "parse.h"
3940
#include "timer.h"
4041
#include "checkpoint.h"
@@ -1132,7 +1133,7 @@ int main(int argc, char **argv)
11321133
mystuff.gpu_sieve_size = GPU_SIEVE_SIZE_DEFAULT * 1024 * 1024;
11331134
/* Default to 16 Kib processed by each block in a Barrett kernel. */
11341135
mystuff.gpu_sieve_processing_size = GPU_SIEVE_PROCESS_SIZE_DEFAULT * 1024;
1135-
strcpy(mystuff.inifile, "mfakto.ini");
1136+
snprintf(mystuff.inifile, sizeof(mystuff.inifile), CFG_FILE);
11361137
mystuff.force_rebuild = 0;
11371138

11381139

src/myfnmatch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ static int match_bracket(const char *p, int k, int kfold)
143143
wchar_t wc2;
144144
int l = mbtowc(&wc2, p+1, 4);
145145
if (l < 0) return 0;
146-
if (wc <= wc2)
147-
if ((unsigned)k-wc <= wc2-wc ||
148-
(unsigned)kfold-wc <= wc2-wc)
146+
if (wc <= wc2) {
147+
unsigned int wc_temp = wc2 - wc;
148+
if ((unsigned)k - wc <= wc_temp || (unsigned)kfold - wc <= wc_temp)
149149
return !inv;
150+
}
150151
p += l-1;
151152
continue;
152153
}

src/output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void print_help(char *string)
5252
printf(" -v <n> verbosity level: terse = 0, default = 1, more = 2,\n");
5353
printf(" maximum = 3\n");
5454
printf(" -tf <exp> <min> <max> trial factor M<exp> from <min> to <max> bits, ignores\n");
55-
printf(" worktodo file\n");
56-
printf(" -i | --inifile <file> load a specific INI file (default: mfakto.ini)\n");
55+
printf(" %s file\n", WORKTODO_FILE);
56+
printf(" -i | --inifile <file> load a specific INI file (default: %s)\n", CFG_FILE);
5757
printf(" -st self-test using the optimal kernel for each test case\n");
5858
printf(" -st2 self-test using all possible kernels\n");
5959
printf("\n");

src/params.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ from 2^66 to 2^67. The OpenCL version, mfakto, requires MORE_CLASSES be defined.
130130
#define MORE_CLASSES
131131

132132

133-
134133
/*
135134
THREADS_PER_BLOCK is not needed for OpenCL - it dynamically uses the device's maximum
136135
All GPU-sieve kernels also have 256 threads per block.
@@ -139,7 +138,6 @@ All GPU-sieve kernels also have 256 threads per block.
139138
//#define THREADS_PER_BLOCK 256
140139

141140

142-
143141
/*
144142
SIEVE_PRIMES defines how far we sieve the factor candidates.
145143
The first <SIEVE_PRIMES> odd primes are sieved.
@@ -213,7 +211,7 @@ Larger values may lead to less wasted cycles by reducing the number of times all
213211
are not TFing a candidate. However, more shared memory is used which may reduce occupancy.
214212
Smaller values should lead to a more responsive system (each kernel takes less time to execute).
215213
216-
The actual configuration is done in mfaktc.ini.
214+
The actual configuration is done in mfakto.ini.
217215
The following lines define the min, default and max value.
218216
*/
219217

@@ -229,15 +227,22 @@ The following lines define the min, default and max value.
229227
#define GPU_SIEVE_PROCESS_SIZE_DEFAULT 16 /* Default is processing 16K bits */
230228
#define GPU_SIEVE_PROCESS_SIZE_MAX 32 /* Upper limit is 64K, since we store k values as "short". Shared memory requirements limit usable values */
231229

232-
/* For worktodo.txt files */
233-
#define MAX_LINE_LENGTH 100
230+
/* settings related to worktodo.txt file */
231+
#define WORKTODO_FILE "worktodo.txt" // should not exceed 50 characters
232+
#define MAX_LINE_LENGTH 100
233+
234+
#define MAX_FACTORS_PER_JOB 20
235+
#define MAX_DEZ_96_STRING_LENGTH 30 // unsigned int96 can have up to 29 digits + 1 byte for NUL
234236

235-
#define MAX_FACTORS_PER_JOB 20
236-
#define MAX_DEZ_96_STRING_LENGTH 30 // max value of int96 (unsigned) has 29 digits + 1 byte for NUL
237+
#define MAX_FACTOR_BUFFER_LENGTH MAX_FACTORS_PER_JOB * MAX_DEZ_96_STRING_LENGTH
238+
#define MAX_BUFFER_LENGTH MAX_FACTOR_BUFFER_LENGTH + 100
237239

238-
#define MAX_FACTOR_BUFFER_LENGTH MAX_FACTORS_PER_JOB * MAX_DEZ_96_STRING_LENGTH
239-
#define MAX_BUFFER_LENGTH MAX_FACTOR_BUFFER_LENGTH + 100
240+
/* other files */
241+
#define CFG_FILE "mfakto.ini"
242+
#define RESULTS_FILE "results.txt"
243+
#define RESULTS_JSON_FILE "results.json.txt"
240244

241-
#define GHZDAYS_MAGIC_TF_TOP 0.016968 // magic constant for TF to 65 bits and above
242-
#define GHZDAYS_MAGIC_TF_MID 0.017832 // magic constant for 63 and 64 bits
243-
#define GHZDAYS_MAGIC_TF_BOT 0.011160 // magic constant for 62 bits and below
245+
/* for GHz-day calculations */
246+
#define GHZDAYS_MAGIC_TF_TOP 0.016968 // magic constant for TF to 65 bits and above
247+
#define GHZDAYS_MAGIC_TF_MID 0.017832 // magic constant for 63 and 64 bits
248+
#define GHZDAYS_MAGIC_TF_BOT 0.011160 // magic constant for 62 bits and below

src/read_config.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ int read_config(mystuff_t *mystuff)
497497

498498
if(my_read_string(mystuff->inifile, "WorkFile", mystuff->workfile, 50))
499499
{
500-
sprintf(mystuff->workfile, "worktodo.txt");
500+
snprintf(mystuff->workfile, sizeof(mystuff->workfile), WORKTODO_FILE);
501501
logprintf(mystuff, "Warning: Cannot read WorkFile from INI file, using default (%s)\n", mystuff->workfile);
502502
}
503503
if(mystuff->verbosity >= 1)logprintf(mystuff, " WorkFile %s\n", mystuff->workfile);
@@ -506,7 +506,7 @@ int read_config(mystuff_t *mystuff)
506506

507507
if(my_read_string(mystuff->inifile, "ResultsFile", mystuff->resultfile, 50))
508508
{
509-
sprintf(mystuff->resultfile, "results.txt");
509+
snprintf(mystuff->resultfile, sizeof(mystuff->resultfile), RESULTS_FILE);
510510
logprintf(mystuff, "Warning: Cannot read ResultsFile from INI file, using default (%s)\n", mystuff->resultfile);
511511
}
512512
if(mystuff->verbosity >= 1)logprintf(mystuff, " ResultsFile %s\n", mystuff->resultfile);
@@ -515,7 +515,7 @@ int read_config(mystuff_t *mystuff)
515515

516516
if (my_read_string(mystuff->inifile, "JSONResultsFile", mystuff->jsonresultfile, 50))
517517
{
518-
sprintf(mystuff->jsonresultfile, "results.json.txt");
518+
snprintf(mystuff->jsonresultfile, sizeof(mystuff->jsonresultfile), RESULTS_JSON_FILE);
519519
logprintf(mystuff, "Warning: Cannot read JSONResultsFile from INI file, using default (%s)\n", mystuff->jsonresultfile);
520520
}
521521
if (mystuff->verbosity >= 1)logprintf(mystuff, " JSONResultsFile %s\n", mystuff->jsonresultfile);

0 commit comments

Comments
 (0)