diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-03 21:34:03 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-03 21:34:03 +0200 |
| commit | 757a732336ee5f0f4b0ba44ac138210c2c1ef805 (patch) | |
| tree | dcd54a6b676215c73d8ae5b1e6de5b169452c2e4 /src | |
| parent | 41fd9c1b91304e7cfb52ed0a3964aa22fcc37c2e (diff) | |
| download | nissy-core-757a732336ee5f0f4b0ba44ac138210c2c1ef805.tar.gz nissy-core-757a732336ee5f0f4b0ba44ac138210c2c1ef805.zip | |
Remove more locks
Diffstat (limited to 'src')
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index ce02946..6db3998 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -59,7 +59,6 @@ typedef struct { | |||
| 59 | cube_t *crep; | 59 | cube_t *crep; |
| 60 | uint64_t start; | 60 | uint64_t start; |
| 61 | uint64_t end; | 61 | uint64_t end; |
| 62 | uint64_t count; | ||
| 63 | pthread_mutex_t *table_mutex[CHUNKS]; | 62 | pthread_mutex_t *table_mutex[CHUNKS]; |
| 64 | } h48h0k4_bfs_arg_t; | 63 | } h48h0k4_bfs_arg_t; |
| 65 | 64 | ||
| @@ -96,7 +95,7 @@ STATIC size_t gendata_h48(gendata_h48_arg_t *); | |||
| 96 | STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); | 95 | STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); |
| 97 | STATIC size_t gendata_h48k2(gendata_h48_arg_t *); | 96 | STATIC size_t gendata_h48k2(gendata_h48_arg_t *); |
| 98 | STATIC void * gendata_h48h0k4_runthread(void *); | 97 | STATIC void * gendata_h48h0k4_runthread(void *); |
| 99 | STATIC_INLINE uint64_t gendata_h48_mark(gendata_h48_mark_t *); | 98 | STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t *); |
| 100 | STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); | 99 | STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); |
| 101 | STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); | 100 | STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); |
| 102 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); | 101 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); |
| @@ -208,7 +207,8 @@ STATIC size_t | |||
| 208 | gendata_h48h0k4(gendata_h48_arg_t *arg) | 207 | gendata_h48h0k4(gendata_h48_arg_t *arg) |
| 209 | { | 208 | { |
| 210 | _Atomic uint8_t *table; | 209 | _Atomic uint8_t *table; |
| 211 | int64_t sc, done, d, h48max; | 210 | uint8_t val; |
| 211 | int64_t i, sc, done, d, h48max; | ||
| 212 | uint64_t t, tt, isize, cc; | 212 | uint64_t t, tt, isize, cc; |
| 213 | h48h0k4_bfs_arg_t bfsarg[THREADS]; | 213 | h48h0k4_bfs_arg_t bfsarg[THREADS]; |
| 214 | pthread_t thread[THREADS]; | 214 | pthread_t thread[THREADS]; |
| @@ -261,14 +261,16 @@ gendata_h48h0k4(gendata_h48_arg_t *arg) | |||
| 261 | 261 | ||
| 262 | for (t = 0; t < THREADS; t++) { | 262 | for (t = 0; t < THREADS; t++) { |
| 263 | bfsarg[t].depth = d; | 263 | bfsarg[t].depth = d; |
| 264 | bfsarg[t].count = 0; | ||
| 265 | pthread_create(&thread[t], NULL, | 264 | pthread_create(&thread[t], NULL, |
| 266 | gendata_h48h0k4_runthread, &bfsarg[t]); | 265 | gendata_h48h0k4_runthread, &bfsarg[t]); |
| 267 | } | 266 | } |
| 268 | 267 | ||
| 269 | for (t = 0, cc = 0; t < THREADS; t++) { | 268 | for (t = 0; t < THREADS; t++) |
| 270 | pthread_join(thread[t], NULL); | 269 | pthread_join(thread[t], NULL); |
| 271 | cc += bfsarg[t].count; | 270 | |
| 271 | for (i = 0, cc = 0; i < h48max; i++) { | ||
| 272 | val = get_h48_pval((uint8_t *)table, i, 4); | ||
| 273 | cc += val == d; | ||
| 272 | } | 274 | } |
| 273 | 275 | ||
| 274 | done += cc; | 276 | done += cc; |
| @@ -290,7 +292,7 @@ gendata_h48h0k4_runthread(void *arg) | |||
| 290 | static const uint8_t breakpoint = 10; /* Hand-picked optimal */ | 292 | static const uint8_t breakpoint = 10; /* Hand-picked optimal */ |
| 291 | 293 | ||
| 292 | uint8_t c, m; | 294 | uint8_t c, m; |
| 293 | uint64_t i, d; | 295 | uint64_t i; |
| 294 | int64_t j; | 296 | int64_t j; |
| 295 | cube_t cube, moved; | 297 | cube_t cube, moved; |
| 296 | gendata_h48_mark_t markarg; | 298 | gendata_h48_mark_t markarg; |
| @@ -312,7 +314,7 @@ gendata_h48h0k4_runthread(void *arg) | |||
| 312 | * If depth < breakpoint, scan all neighbors of coordinates at depth-1. | 314 | * If depth < breakpoint, scan all neighbors of coordinates at depth-1. |
| 313 | * Otherwise, scan all neighbors of unvisited coordinates. | 315 | * Otherwise, scan all neighbors of unvisited coordinates. |
| 314 | */ | 316 | */ |
| 315 | for (i = bfsarg->start, d = 0; i < bfsarg->end; i++) { | 317 | for (i = bfsarg->start; i < bfsarg->end; i++) { |
| 316 | c = get_h48_pval((uint8_t *)bfsarg->table, i, 4); | 318 | c = get_h48_pval((uint8_t *)bfsarg->table, i, 4); |
| 317 | 319 | ||
| 318 | if ((bfsarg->depth < breakpoint && c != bfsarg->depth - 1) || | 320 | if ((bfsarg->depth < breakpoint && c != bfsarg->depth - 1) || |
| @@ -328,19 +330,17 @@ gendata_h48h0k4_runthread(void *arg) | |||
| 328 | if (c <= bfsarg->depth) | 330 | if (c <= bfsarg->depth) |
| 329 | continue; | 331 | continue; |
| 330 | markarg.cube = moved; | 332 | markarg.cube = moved; |
| 331 | d += gendata_h48_mark(&markarg); | 333 | gendata_h48_mark(&markarg); |
| 332 | } else { | 334 | } else { |
| 333 | if (c >= bfsarg->depth) | 335 | if (c >= bfsarg->depth) |
| 334 | continue; | 336 | continue; |
| 335 | markarg.cube = cube; | 337 | markarg.cube = cube; |
| 336 | d += gendata_h48_mark(&markarg); | 338 | gendata_h48_mark(&markarg); |
| 337 | break; /* Enough to find one, skip the rest */ | 339 | break; /* Enough to find one, skip the rest */ |
| 338 | } | 340 | } |
| 339 | } | 341 | } |
| 340 | } | 342 | } |
| 341 | 343 | ||
| 342 | bfsarg->count += d; | ||
| 343 | |||
| 344 | return NULL; | 344 | return NULL; |
| 345 | } | 345 | } |
| 346 | 346 | ||
| @@ -428,7 +428,6 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 428 | 428 | ||
| 429 | h48map_destroy(&shortcubes); | 429 | h48map_destroy(&shortcubes); |
| 430 | 430 | ||
| 431 | /* TODO: inline into mark */ | ||
| 432 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { | 431 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { |
| 433 | t = get_h48_pval((uint8_t *)table, j, 2); | 432 | t = get_h48_pval((uint8_t *)table, j, 2); |
| 434 | arg->info.distribution[t]++; | 433 | arg->info.distribution[t]++; |
| @@ -557,26 +556,23 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | |||
| 557 | } | 556 | } |
| 558 | } | 557 | } |
| 559 | 558 | ||
| 560 | STATIC_INLINE uint64_t | 559 | STATIC_INLINE void |
| 561 | gendata_h48_mark(gendata_h48_mark_t *arg) | 560 | gendata_h48_mark(gendata_h48_mark_t *arg) |
| 562 | { | 561 | { |
| 563 | uint8_t oldval, newval; | 562 | uint8_t oldval, newval; |
| 564 | uint64_t d; | ||
| 565 | int64_t coord, mutex; | 563 | int64_t coord, mutex; |
| 566 | 564 | ||
| 567 | d = 0; | ||
| 568 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, | 565 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, |
| 569 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); | 566 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); |
| 570 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | ||
| 571 | pthread_mutex_lock(arg->table_mutex[mutex]); | ||
| 572 | oldval = get_h48_pval((uint8_t *)arg->table, coord, arg->k); | 567 | oldval = get_h48_pval((uint8_t *)arg->table, coord, arg->k); |
| 573 | newval = (uint8_t)MAX(arg->depth, 0); | 568 | newval = (uint8_t)MAX(arg->depth, 0); |
| 574 | d += newval < oldval; | 569 | if (newval < oldval) { |
| 575 | set_h48_pval(arg->table, coord, arg->k, MIN(oldval, newval)); | 570 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; |
| 576 | pthread_mutex_unlock(arg->table_mutex[mutex]); | 571 | pthread_mutex_lock(arg->table_mutex[mutex]); |
| 572 | set_h48_pval(arg->table, coord, arg->k, newval); | ||
| 573 | pthread_mutex_unlock(arg->table_mutex[mutex]); | ||
| 574 | } | ||
| 577 | ) | 575 | ) |
| 578 | |||
| 579 | return d; | ||
| 580 | } | 576 | } |
| 581 | 577 | ||
| 582 | STATIC_INLINE bool | 578 | STATIC_INLINE bool |
