aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-20 10:18:55 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-20 10:18:55 +0200
commit89e0bc567960199dec774e5449e471dd31ef440b (patch)
tree6a420bfbaa852b124a56941e05de8698b453d38a
parent37899ca61e17543c4bd5131ef76f655684d1faa7 (diff)
downloadnissy-core-89e0bc567960199dec774e5449e471dd31ef440b.tar.gz
nissy-core-89e0bc567960199dec774e5449e471dd31ef440b.zip
Simplified code for h4k0
Diffstat (limited to '')
-rw-r--r--src/solvers/h48/gendata_h48.h129
1 files changed, 42 insertions, 87 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 0a6f130..a993f53 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -96,8 +96,6 @@ typedef struct {
96STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); 96STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *);
97STATIC size_t gendata_h48(gendata_h48_arg_t *); 97STATIC size_t gendata_h48(gendata_h48_arg_t *);
98STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); 98STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *);
99STATIC void gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *);
100STATIC void gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *);
101STATIC size_t gendata_h48k2(gendata_h48_arg_t *); 99STATIC size_t gendata_h48k2(gendata_h48_arg_t *);
102STATIC void * gendata_h48h0k4_runthread(void *); 100STATIC void * gendata_h48h0k4_runthread(void *);
103STATIC_INLINE uint64_t gendata_h48_mark(gendata_h48_mark_t *); 101STATIC_INLINE uint64_t gendata_h48_mark(gendata_h48_mark_t *);
@@ -291,111 +289,68 @@ gendata_h48h0k4_runthread(void *arg)
291{ 289{
292 static const uint8_t breakpoint = 10; /* Hand-picked optimal */ 290 static const uint8_t breakpoint = 10; /* Hand-picked optimal */
293 291
294 h48h0k4_bfs_arg_t *bfsarg;
295
296 bfsarg = (h48h0k4_bfs_arg_t *)arg;
297
298 if (bfsarg->depth < breakpoint)
299 gendata_h48h0k4_bfs_fromdone(bfsarg);
300 else
301 gendata_h48h0k4_bfs_fromnew(bfsarg);
302
303 return NULL;
304}
305
306STATIC void
307gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg)
308{
309 uint8_t c, m; 292 uint8_t c, m;
310 uint64_t i, d, mutex; 293 uint64_t i, d, mutex;
311 int64_t j; 294 int64_t j;
312 cube_t cube, moved; 295 cube_t cube, moved;
313 gendata_h48_mark_t markarg; 296 gendata_h48_mark_t markarg;
297 h48h0k4_bfs_arg_t *bfsarg;
314 298
315 markarg = (gendata_h48_mark_t) { 299 bfsarg = (h48h0k4_bfs_arg_t *)arg;
316 .depth = arg->depth,
317 .h = 0,
318 .k = 4,
319 .cocsepdata = arg->cocsepdata,
320 .selfsim = arg->selfsim,
321 .table = arg->table,
322 .table_mutex = arg->table_mutex,
323 };
324
325 for (i = arg->start, d = 0; i < arg->end; i++) {
326 mutex = H48_INDEX(i, 4) % CHUNKS;
327 pthread_mutex_lock(arg->table_mutex[mutex]);
328 c = get_h48_pval(arg->table, i, 4);
329 pthread_mutex_unlock(arg->table_mutex[mutex]);
330 if (c != arg->depth - 1)
331 continue;
332 cube = invcoord_h48(i, arg->crep, 0);
333 for (m = 0; m < 18; m++) {
334 moved = move(cube, m);
335 j = coord_h48(moved, arg->cocsepdata, 0);
336 mutex = H48_INDEX(j, 4) % CHUNKS;
337 pthread_mutex_lock(arg->table_mutex[mutex]);
338 c = get_h48_pval(arg->table, j, 4);
339 pthread_mutex_unlock(arg->table_mutex[mutex]);
340 if (c <= arg->depth)
341 continue;
342 markarg.cube = moved;
343 d += gendata_h48_mark(&markarg);
344 }
345 }
346
347 pthread_mutex_lock(arg->distribution_mutex);
348 arg->count += d;
349 arg->distribution[arg->depth] += d;
350 pthread_mutex_unlock(arg->distribution_mutex);
351}
352
353STATIC void
354gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg)
355{
356 uint8_t c, m, x;
357 uint64_t i, d, mutex;
358 int64_t j;
359 cube_t cube, moved;
360 gendata_h48_mark_t markarg;
361 300
362 markarg = (gendata_h48_mark_t) { 301 markarg = (gendata_h48_mark_t) {
363 .depth = arg->depth, 302 .depth = bfsarg->depth,
364 .h = 0, 303 .h = 0,
365 .k = 4, 304 .k = 4,
366 .cocsepdata = arg->cocsepdata, 305 .cocsepdata = bfsarg->cocsepdata,
367 .selfsim = arg->selfsim, 306 .selfsim = bfsarg->selfsim,
368 .table = arg->table, 307 .table = bfsarg->table,
369 .table_mutex = arg->table_mutex, 308 .table_mutex = bfsarg->table_mutex,
370 }; 309 };
371 310
372 for (i = arg->start, d = 0; i < arg->end; i++) { 311 /*
312 * If depth < breakpoint, scan all neighbors of coordinates at depth-1.
313 * Otherwise, scan all neighbors of unvisited coordinates.
314 */
315 for (i = bfsarg->start, d = 0; i < bfsarg->end; i++) {
373 mutex = H48_INDEX(i, 4) % CHUNKS; 316 mutex = H48_INDEX(i, 4) % CHUNKS;
374 pthread_mutex_lock(arg->table_mutex[mutex]); 317 pthread_mutex_lock(bfsarg->table_mutex[mutex]);
375 c = get_h48_pval(arg->table, i, 4); 318 c = get_h48_pval(bfsarg->table, i, 4);
376 pthread_mutex_unlock(arg->table_mutex[mutex]); 319 pthread_mutex_unlock(bfsarg->table_mutex[mutex]);
377 if (c != 0xF) 320
321 if ((bfsarg->depth < breakpoint && c != bfsarg->depth - 1) ||
322 (bfsarg->depth >= breakpoint && c != 0xF))
378 continue; 323 continue;
379 cube = invcoord_h48(i, arg->crep, 0); 324
325 cube = invcoord_h48(i, bfsarg->crep, 0);
380 for (m = 0; m < 18; m++) { 326 for (m = 0; m < 18; m++) {
381 moved = move(cube, m); 327 moved = move(cube, m);
382 j = coord_h48(moved, arg->cocsepdata, 0); 328 j = coord_h48(moved, bfsarg->cocsepdata, 0);
383 mutex = H48_INDEX(j, 4) % CHUNKS; 329 mutex = H48_INDEX(j, 4) % CHUNKS;
384 pthread_mutex_lock(arg->table_mutex[mutex]); 330 pthread_mutex_lock(bfsarg->table_mutex[mutex]);
385 x = get_h48_pval(arg->table, j, 4); 331 c = get_h48_pval(bfsarg->table, j, 4);
386 pthread_mutex_unlock(arg->table_mutex[mutex]); 332 pthread_mutex_unlock(bfsarg->table_mutex[mutex]);
387 if (x >= arg->depth) 333 if (bfsarg->depth < breakpoint) {
388 continue; 334 if (c <= bfsarg->depth)
389 markarg.cube = cube; 335 continue;
390 d += gendata_h48_mark(&markarg); 336 markarg.cube = moved;
391 break; /* Enough to find one, skip the rest */ 337 d += gendata_h48_mark(&markarg);
338 } else {
339 if (c >= bfsarg->depth)
340 continue;
341 markarg.cube = cube;
342 d += gendata_h48_mark(&markarg);
343 break; /* Enough to find one, skip the rest */
344 }
392 } 345 }
393 } 346 }
394 347
395 pthread_mutex_lock(arg->distribution_mutex); 348 pthread_mutex_lock(bfsarg->distribution_mutex);
396 arg->count += d; 349 bfsarg->count += d;
397 arg->distribution[arg->depth] += d; 350 bfsarg->distribution[bfsarg->depth] += d;
398 pthread_mutex_unlock(arg->distribution_mutex); 351 pthread_mutex_unlock(bfsarg->distribution_mutex);
352
353 return NULL;
399} 354}
400 355
401STATIC size_t 356STATIC size_t

Generated with cgit - Back to sebastiano.tronto.net