aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-11 19:24:15 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-11 22:10:42 +0200
commitc4f64cf2556c0f8597e1fbc19d7c664b8da94612 (patch)
tree67cf5324d089dc8bafa255a5580556ba44361b0d /tools
parent4668156da5915c8d7a7b40edaf6617b004547bd7 (diff)
downloadnissy-core-c4f64cf2556c0f8597e1fbc19d7c664b8da94612.tar.gz
nissy-core-c4f64cf2556c0f8597e1fbc19d7c664b8da94612.zip
Added buffer sizes in API args
Diffstat (limited to '')
-rw-r--r--tools/000_gendata/gendata.c6
-rw-r--r--tools/001_derive_h48/derive_h48.c3
-rw-r--r--tools/100_checkdata/checkdata.c8
-rw-r--r--tools/200_stats_tables_h48/stats_tables_h48.c12
-rw-r--r--tools/300_solve_small/solve_small.c24
-rw-r--r--tools/tool.h7
6 files changed, 33 insertions, 27 deletions
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c
index eec9f76..0d647f9 100644
--- a/tools/000_gendata/gendata.c
+++ b/tools/000_gendata/gendata.c
@@ -17,8 +17,8 @@ run(void) {
17 case -2: 17 case -2:
18 goto gendata_run_finish; 18 goto gendata_run_finish;
19 default: 19 default:
20 nissy_datainfo(buf, write_stdout); 20 nissy_datainfo(size, buf, write_stdout);
21 consistent = nissy_checkdata(solver, buf) == 0; 21 consistent = nissy_checkdata(size, buf) == 0;
22 expected = check_distribution(solver, buf); 22 expected = check_distribution(solver, buf);
23 if (consistent && expected) { 23 if (consistent && expected) {
24 printf("\n"); 24 printf("\n");
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
42 uint8_t h, k; 42 uint8_t h, k;
43 43
44 if (argc < 2) { 44 if (argc < 2) {
45 fprintf(stderr, "Error: not enough arguments. " 45 printf("Error: not enough arguments. "
46 "A solver must be given.\n"); 46 "A solver must be given.\n");
47 return 1; 47 return 1;
48 } 48 }
diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c
index c5f28c8..c964882 100644
--- a/tools/001_derive_h48/derive_h48.c
+++ b/tools/001_derive_h48/derive_h48.c
@@ -19,8 +19,7 @@ void run(void) {
19 19
20int main(int argc, char **argv) { 20int main(int argc, char **argv) {
21 if (argc < 5) { 21 if (argc < 5) {
22 fprintf(stderr, 22 printf("Error: not enough arguments. Required:\n"
23 "Error: not enough arguments. Required:\n"
24 "1. Solver name for large table\n" 23 "1. Solver name for large table\n"
25 "2. Solver name for derived table\n" 24 "2. Solver name for derived table\n"
26 "3. Filename containing large table\n" 25 "3. Filename containing large table\n"
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c
index 695a4dd..2005f17 100644
--- a/tools/100_checkdata/checkdata.c
+++ b/tools/100_checkdata/checkdata.c
@@ -12,19 +12,19 @@ run(void) {
12 size = nissy_datasize(solver); 12 size = nissy_datasize(solver);
13 13
14 if (size <= 0) { 14 if (size <= 0) {
15 fprintf(stderr, "Error in datasize\n"); 15 printf("Error in datasize\n");
16 return; 16 return;
17 } 17 }
18 18
19 if ((f = fopen(filename, "rb")) == NULL) { 19 if ((f = fopen(filename, "rb")) == NULL) {
20 fprintf(stderr, "Error reading file %s\n", filename); 20 printf("Error reading file %s\n", filename);
21 return; 21 return;
22 } 22 }
23 23
24 buf = malloc(size); 24 buf = malloc(size);
25 fread(buf, size, 1, f); 25 fread(buf, size, 1, f);
26 fclose(f); 26 fclose(f);
27 result = nissy_checkdata(solver, buf); 27 result = nissy_checkdata(size, buf);
28 free(buf); 28 free(buf);
29 29
30 printf("checkdata %s\n", result == 0 ? "succeeded" : "failed"); 30 printf("checkdata %s\n", result == 0 ? "succeeded" : "failed");
@@ -34,7 +34,7 @@ run(void) {
34 34
35int main(int argc, char **argv) { 35int main(int argc, char **argv) {
36 if (argc < 3) { 36 if (argc < 3) {
37 fprintf(stderr, "Error: not enough arguments. " 37 printf("Error: not enough arguments. "
38 "A solver and a file name must be given.\n"); 38 "A solver and a file name must be given.\n");
39 return 1; 39 return 1;
40 } 40 }
diff --git a/tools/200_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c
index a9a2a1e..11df137 100644
--- a/tools/200_stats_tables_h48/stats_tables_h48.c
+++ b/tools/200_stats_tables_h48/stats_tables_h48.c
@@ -6,6 +6,7 @@
6#define LOG_EVERY (NCUBES_PER_THREAD / 10) 6#define LOG_EVERY (NCUBES_PER_THREAD / 10)
7 7
8int NCUBES_PER_THREAD; 8int NCUBES_PER_THREAD;
9int64_t size = 0;
9const char *solver = "h48stats"; 10const char *solver = "h48stats";
10const char *filename = "tables/h48h0k4"; 11const char *filename = "tables/h48h0k4";
11char *buf; 12char *buf;
@@ -40,11 +41,12 @@ run_thread(void *arg)
40 cp = rand64(); 41 cp = rand64();
41 co = rand64(); 42 co = rand64();
42 nissy_getcube(ep, eo, cp, co, "fix", cube); 43 nissy_getcube(ep, eo, cp, co, "fix", cube);
43 nissy_solve(cube, "h48stats", "", 0, MAXMOVES, 1, -1, buf, s); 44 nissy_solve(cube, "h48stats", NISSY_NISSFLAG_NORMAL,
45 0, MAXMOVES, 1, -1, size, buf, 12, s);
44 for (j = 0; j < 12; j++) 46 for (j = 0; j < 12; j++)
45 a->v[j][(int)s[j]]++; 47 a->v[j][(int)s[j]]++;
46 if ((i+1) % LOG_EVERY == 0) 48 if ((i+1) % LOG_EVERY == 0)
47 fprintf(stderr, "[thread %d] %d cubes solved...\n", 49 printf("[thread %d] %d cubes solved...\n",
48 a->thread_id, i+1); 50 a->thread_id, i+1);
49 } 51 }
50 52
@@ -57,6 +59,8 @@ void run(void) {
57 pthread_t thread[THREADS]; 59 pthread_t thread[THREADS];
58 thread_arg_t arg[THREADS]; 60 thread_arg_t arg[THREADS];
59 61
62 size = nissy_datasize(solver);
63
60 for (i = 0; i < THREADS; i++) { 64 for (i = 0; i < THREADS; i++) {
61 arg[i] = (thread_arg_t) { 65 arg[i] = (thread_arg_t) {
62 .thread_id = i, 66 .thread_id = i,
@@ -88,7 +92,7 @@ int main(int argc, char **argv) {
88 nissy_setlogger(log_stderr); 92 nissy_setlogger(log_stderr);
89 93
90 if (argc < 2) { 94 if (argc < 2) {
91 fprintf(stderr, "Error: not enough arguments. " 95 printf("Error: not enough arguments. "
92 "Number of cubes per thread must be provided.\n"); 96 "Number of cubes per thread must be provided.\n");
93 return 1; 97 return 1;
94 } 98 }
@@ -96,7 +100,7 @@ int main(int argc, char **argv) {
96 NCUBES_PER_THREAD = atoi(argv[1]); 100 NCUBES_PER_THREAD = atoi(argv[1]);
97 101
98 if (NCUBES_PER_THREAD < 1 || NCUBES_PER_THREAD > 1000000) { 102 if (NCUBES_PER_THREAD < 1 || NCUBES_PER_THREAD > 1000000) {
99 fprintf(stderr, "Invalid number of cubes: must be > 0 and " 103 printf("Invalid number of cubes: must be > 0 and "
100 "< 1000000, but %d was given.\n", NCUBES_PER_THREAD); 104 "< 1000000, but %d was given.\n", NCUBES_PER_THREAD);
101 return 1; 105 return 1;
102 } 106 }
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c
index ade949a..5400436 100644
--- a/tools/300_solve_small/solve_small.c
+++ b/tools/300_solve_small/solve_small.c
@@ -1,6 +1,9 @@
1#include "../tool.h" 1#include "../tool.h"
2 2
3#define SOL_BUFFER_LEN 1000
4
3const char *solver = "h48h0k4"; 5const char *solver = "h48h0k4";
6int64_t size = 0;
4char *buf; 7char *buf;
5 8
6char *scrambles[] = { 9char *scrambles[] = {
@@ -14,25 +17,22 @@ char *scrambles[] = {
14void run(void) { 17void run(void) {
15 int i; 18 int i;
16 int64_t n; 19 int64_t n;
17 char sol[100], cube[22]; 20 char sol[SOL_BUFFER_LEN], cube[22];
18 21
19 printf("Solved the following scrambles:\n\n"); 22 printf("Solved the following scrambles:\n\n");
20 for (i = 0; scrambles[i] != NULL; i++) { 23 for (i = 0; scrambles[i] != NULL; i++) {
21 printf("%d. %s\n", i+1, scrambles[i]); 24 printf("%d. %s\n", i+1, scrambles[i]);
22 fprintf(stderr, "Solving scramble %s\n", scrambles[i]); 25 printf("Solving scramble %s\n", scrambles[i]);
23 if (nissy_frommoves(scrambles[i], cube) == -1) { 26 if (nissy_frommoves(scrambles[i], cube) == -1) {
24 fprintf(stderr, "Invalid scramble\n"); 27 printf("Invalid scramble\n");
25 printf("Invalid\n");
26 continue; 28 continue;
27 } 29 }
28 n = nissy_solve( 30 n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL,
29 cube, solver, "", 0, 20, 1, -1, buf, sol); 31 0, 20, 1, -1, size, buf, SOL_BUFFER_LEN, sol);
30 if (n == 0) { 32 if (n == 0)
31 printf("No solution\n"); 33 printf("No solution found\n");
32 fprintf(stderr, "No solution found\n"); 34 else
33 } else {
34 printf("Solutions:\n%s\n", sol); 35 printf("Solutions:\n%s\n", sol);
35 }
36 } 36 }
37} 37}
38 38
@@ -46,6 +46,8 @@ int main(void) {
46 if (getdata(solver, &buf, filename) != 0) 46 if (getdata(solver, &buf, filename) != 0)
47 return 1; 47 return 1;
48 48
49 size = nissy_datasize(solver);
50
49 timerun(run); 51 timerun(run);
50 52
51 free(buf); 53 free(buf);
diff --git a/tools/tool.h b/tools/tool.h
index 02ff0f2..2fc0224 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -96,7 +96,7 @@ generatetable(const char *solver, char **buf)
96 } 96 }
97 97
98 *buf = malloc(size); 98 *buf = malloc(size);
99 gensize = nissy_gendata(solver, *buf); 99 gensize = nissy_gendata(solver, size, *buf);
100 100
101 if (gensize != size) { 101 if (gensize != size) {
102 printf("Error generating table"); 102 printf("Error generating table");
@@ -212,7 +212,7 @@ gendata_run(
212 case -2: 212 case -2:
213 goto gendata_run_finish; 213 goto gendata_run_finish;
214 default: 214 default:
215 nissy_datainfo(buf, write_stdout); 215 nissy_datainfo(size, buf, write_stdout);
216 printf("\n"); 216 printf("\n");
217 printf("Succesfully generated %" PRId64 " bytes. " 217 printf("Succesfully generated %" PRId64 " bytes. "
218 "See above for details on the tables.\n", size); 218 "See above for details on the tables.\n", size);
@@ -237,6 +237,7 @@ derivedata_run(
237 int64_t size; 237 int64_t size;
238 char *buf; 238 char *buf;
239 239
240 buf = NULL;
240 size = derivetable(solver_large, solver_small, filename_large, &buf); 241 size = derivetable(solver_large, solver_small, filename_large, &buf);
241 switch (size) { 242 switch (size) {
242 case -1: 243 case -1:
@@ -244,7 +245,7 @@ derivedata_run(
244 case -2: 245 case -2:
245 goto derivedata_run_finish; 246 goto derivedata_run_finish;
246 default: 247 default:
247 nissy_datainfo(buf, write_stdout); 248 nissy_datainfo(size, buf, write_stdout);
248 printf("\n"); 249 printf("\n");
249 printf("Succesfully generated %" PRId64 " bytes. " 250 printf("Succesfully generated %" PRId64 " bytes. "
250 "See above for details on the tables.\n", size); 251 "See above for details on the tables.\n", size);

Generated with cgit - Back to sebastiano.tronto.net