aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/h48')
-rw-r--r--src/solvers/h48/solve.h25
-rw-r--r--src/solvers/h48/solve_multithread.h25
2 files changed, 28 insertions, 22 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 67c596b..d506596 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -17,8 +17,8 @@ typedef struct {
17 uint8_t nissbranch; 17 uint8_t nissbranch;
18 int8_t npremoves; 18 int8_t npremoves;
19 uint8_t premoves[MAXLEN]; 19 uint8_t premoves[MAXLEN];
20 _Atomic long long *nodes_visited; 20 long long nodes_visited;
21 _Atomic long long *table_fallbacks; 21 long long table_fallbacks;
22} dfsarg_solveh48_t; 22} dfsarg_solveh48_t;
23 23
24STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint8_t); 24STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint8_t);
@@ -105,7 +105,7 @@ solve_h48_stop(dfsarg_solveh48_t *arg)
105 int8_t cbound, cbound_inv, h48bound, h48bound_inv; 105 int8_t cbound, cbound_inv, h48bound, h48bound_inv;
106 int64_t coord, coord_inv; 106 int64_t coord, coord_inv;
107 107
108 (*arg->nodes_visited)++; 108 arg->nodes_visited++;
109 109
110 arg->nissbranch = MM_NORMAL; 110 arg->nissbranch = MM_NORMAL;
111 cbound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); 111 cbound = get_h48_cdata(arg->cube, arg->cocsepdata, &data);
@@ -124,7 +124,7 @@ solve_h48_stop(dfsarg_solveh48_t *arg)
124 124
125 if (arg->k == 2) { 125 if (arg->k == 2) {
126 if (h48bound == 0) { 126 if (h48bound == 0) {
127 (*arg->table_fallbacks)++; 127 arg->table_fallbacks++;
128 h48bound = get_h48_pval( 128 h48bound = get_h48_pval(
129 arg->h48data_fallback, coord >> arg->h, 4); 129 arg->h48data_fallback, coord >> arg->h, 4);
130 } else { 130 } else {
@@ -141,7 +141,7 @@ solve_h48_stop(dfsarg_solveh48_t *arg)
141 h48bound_inv = get_h48_pval(arg->h48data, coord_inv, arg->k); 141 h48bound_inv = get_h48_pval(arg->h48data, coord_inv, arg->k);
142 if (arg->k == 2) { 142 if (arg->k == 2) {
143 if (h48bound_inv == 0) { 143 if (h48bound_inv == 0) {
144 (*arg->table_fallbacks)++; 144 arg->table_fallbacks++;
145 h48bound_inv = get_h48_pval( 145 h48bound_inv = get_h48_pval(
146 arg->h48data_fallback, coord_inv >> arg->h, 4); 146 arg->h48data_fallback, coord_inv >> arg->h, 4);
147 } else { 147 } else {
@@ -203,6 +203,8 @@ solve_h48_dfs(dfsarg_solveh48_t *arg)
203 } 203 }
204 } 204 }
205 205
206 arg->nodes_visited = nextarg.nodes_visited;
207 arg->table_fallbacks = nextarg.table_fallbacks;
206 return ret; 208 return ret;
207} 209}
208 210
@@ -220,14 +222,12 @@ solve_h48(
220) 222)
221{ 223{
222 _Atomic int64_t nsols; 224 _Atomic int64_t nsols;
223 _Atomic long long nodes, fallbacks;
224 dfsarg_solveh48_t arg; 225 dfsarg_solveh48_t arg;
225 tableinfo_t info, fbinfo; 226 tableinfo_t info, fbinfo;
226 227
227 if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) 228 if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK)
228 goto solve_h48_error_data; 229 goto solve_h48_error_data;
229 230
230 nodes = fallbacks = 0;
231 arg = (dfsarg_solveh48_t) { 231 arg = (dfsarg_solveh48_t) {
232 .cube = cube, 232 .cube = cube,
233 .inverse = inverse(cube), 233 .inverse = inverse(cube),
@@ -240,8 +240,8 @@ solve_h48(
240 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, 240 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE,
241 .solutions_size = solutions_size, 241 .solutions_size = solutions_size,
242 .nextsol = &solutions, 242 .nextsol = &solutions,
243 .nodes_visited = &nodes, 243 .nodes_visited = 0,
244 .table_fallbacks = &fallbacks 244 .table_fallbacks = 0
245 }; 245 };
246 246
247 if (info.bits == 2) { 247 if (info.bits == 2) {
@@ -268,9 +268,10 @@ solve_h48(
268 } 268 }
269 **arg.nextsol = '\0'; 269 **arg.nextsol = '\0';
270 270
271 stats[0] = nodes; 271 stats[0] = arg.nodes_visited;
272 stats[1] = fallbacks; 272 stats[1] = arg.table_fallbacks;
273 LOG("Nodes visited: %lld\nTable fallbacks: %lld\n", nodes, fallbacks); 273 LOG("Nodes visited: %lld\nTable fallbacks: %lld\n",
274 arg.nodes_visited, arg.table_fallbacks);
274 275
275 return nsols; 276 return nsols;
276 277
diff --git a/src/solvers/h48/solve_multithread.h b/src/solvers/h48/solve_multithread.h
index 394350e..72f519e 100644
--- a/src/solvers/h48/solve_multithread.h
+++ b/src/solvers/h48/solve_multithread.h
@@ -11,6 +11,8 @@ typedef struct {
11 pthread_cond_t cond; 11 pthread_cond_t cond;
12 pthread_cond_t active_cond; 12 pthread_cond_t active_cond;
13 atomic_bool terminate; 13 atomic_bool terminate;
14 _Atomic long long nodes_visited_global;
15 _Atomic long long table_fallbacks_global;
14} task_queue_t; 16} task_queue_t;
15 17
16STATIC void solve_h48_appendsolution_thread(dfsarg_solveh48_t *, task_queue_t *); 18STATIC void solve_h48_appendsolution_thread(dfsarg_solveh48_t *, task_queue_t *);
@@ -128,6 +130,8 @@ start_thread(void *arg)
128 pthread_mutex_unlock(&queue->mutex); 130 pthread_mutex_unlock(&queue->mutex);
129 131
130 solve_h48_single(&task, queue); 132 solve_h48_single(&task, queue);
133 queue->nodes_visited_global += task.nodes_visited;
134 queue->table_fallbacks_global += task.table_fallbacks;
131 135
132 pthread_mutex_lock(&queue->mutex); 136 pthread_mutex_lock(&queue->mutex);
133 queue->active--; 137 queue->active--;
@@ -243,6 +247,9 @@ solve_h48_single(dfsarg_solveh48_t *arg, task_queue_t *tq)
243 } 247 }
244 } 248 }
245 } 249 }
250
251 arg->nodes_visited = nextarg.nodes_visited;
252 arg->table_fallbacks = nextarg.table_fallbacks;
246 return ret; 253 return ret;
247} 254}
248 255
@@ -260,7 +267,6 @@ solve_h48_multithread(
260) 267)
261{ 268{
262 _Atomic int64_t nsols = 0; 269 _Atomic int64_t nsols = 0;
263 _Atomic long long nodes, fallbacks;
264 int p_depth = 0; 270 int p_depth = 0;
265 dfsarg_solveh48_t arg; 271 dfsarg_solveh48_t arg;
266 tableinfo_t info, fbinfo; 272 tableinfo_t info, fbinfo;
@@ -269,7 +275,6 @@ solve_h48_multithread(
269 if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) 275 if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK)
270 goto solve_h48_multithread_error_data; 276 goto solve_h48_multithread_error_data;
271 277
272 nodes = fallbacks = 0;
273 arg = (dfsarg_solveh48_t){ 278 arg = (dfsarg_solveh48_t){
274 .cube = cube, 279 .cube = cube,
275 .inverse = inverse(cube), 280 .inverse = inverse(cube),
@@ -283,8 +288,8 @@ solve_h48_multithread(
283 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, 288 .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE,
284 .solutions_size = solutions_size, 289 .solutions_size = solutions_size,
285 .nextsol = &solutions, 290 .nextsol = &solutions,
286 .nodes_visited = &nodes, 291 .nodes_visited = 0,
287 .table_fallbacks = &fallbacks 292 .table_fallbacks = 0
288 }; 293 };
289 294
290 if (info.bits == 2) { 295 if (info.bits == 2) {
@@ -306,6 +311,7 @@ solve_h48_multithread(
306 task_queue_t nq; 311 task_queue_t nq;
307 init_queue(&nq); 312 init_queue(&nq);
308 313
314 nq.nodes_visited_global = nq.table_fallbacks_global = 0;
309 for (int i = 0; i < THREADS; i++) { 315 for (int i = 0; i < THREADS; i++) {
310 pthread_create(&threads[i], NULL, &start_thread, &nq); 316 pthread_create(&threads[i], NULL, &start_thread, &nq);
311 } 317 }
@@ -333,13 +339,12 @@ solve_h48_multithread(
333 } 339 }
334 **arg.nextsol = '\0'; 340 **arg.nextsol = '\0';
335 341
336 stats[0] = nodes; 342 stats[0] = nq.nodes_visited_global;
337 stats[1] = fallbacks; 343 stats[1] = nq.table_fallbacks_global;
338 LOG("Nodes visited: %lld\nTable fallbacks: %lld\n", nodes, fallbacks); 344 LOG("Nodes visited: %lld\nTable fallbacks: %lld\n",
345 nq.nodes_visited_global, nq.table_fallbacks_global);
339 346
340 return nsols; 347 return nsols;
341 348
342solve_h48_multithread_error_data: 349solve_h48_multithread_error_data: LOG("solve_h48: error reading table\n"); return NISSY_ERROR_DATA;
343 LOG("solve_h48: error reading table\n");
344 return NISSY_ERROR_DATA;
345} 350}

Generated with cgit - Back to sebastiano.tronto.net