diff options
Diffstat (limited to 'src/pruning.c')
| -rw-r--r-- | src/pruning.c | 89 |
1 files changed, 68 insertions, 21 deletions
diff --git a/src/pruning.c b/src/pruning.c index 6cab7e7..3ca9fac 100644 --- a/src/pruning.c +++ b/src/pruning.c | |||
| @@ -6,9 +6,10 @@ | |||
| 6 | static int findchunk(PruneData *pd, int nchunks, uint64_t i); | 6 | static int findchunk(PruneData *pd, int nchunks, uint64_t i); |
| 7 | static void genptable_bfs(PruneData *pd, int d, int nt, int nc); | 7 | static void genptable_bfs(PruneData *pd, int d, int nt, int nc); |
| 8 | static void genptable_compress(PruneData *pd); | 8 | static void genptable_compress(PruneData *pd); |
| 9 | static void genptable_fixnasty(PruneData *pd, int d); | 9 | static void genptable_fixnasty(PruneData *pd, int d, int nthreads); |
| 10 | static void genptable_setbase(PruneData *pd); | 10 | static void genptable_setbase(PruneData *pd); |
| 11 | static void * instance_bfs(void *arg); | 11 | static void * instance_bfs(void *arg); |
| 12 | static void * instance_fixnasty(void *arg); | ||
| 12 | static void ptable_update(PruneData *pd, Cube cube, int m); | 13 | static void ptable_update(PruneData *pd, Cube cube, int m); |
| 13 | static void ptable_update_index(PruneData *pd, uint64_t ind, int m); | 14 | static void ptable_update_index(PruneData *pd, uint64_t ind, int m); |
| 14 | static int ptableval_index(PruneData *pd, uint64_t ind); | 15 | static int ptableval_index(PruneData *pd, uint64_t ind); |
| @@ -171,7 +172,7 @@ genptable(PruneData *pd, int nthreads) | |||
| 171 | ptable_update(pd, (Cube){0}, 0); | 172 | ptable_update(pd, (Cube){0}, 0); |
| 172 | pd->n = 1; | 173 | pd->n = 1; |
| 173 | oldn = 0; | 174 | oldn = 0; |
| 174 | genptable_fixnasty(pd, 0); | 175 | genptable_fixnasty(pd, 0, nthreads); |
| 175 | fprintf(stderr, "Depth %d done, generated %" | 176 | fprintf(stderr, "Depth %d done, generated %" |
| 176 | PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", | 177 | PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", |
| 177 | 0, pd->n - oldn, pd->n, pd->coord->max); | 178 | 0, pd->n - oldn, pd->n, pd->coord->max); |
| @@ -179,7 +180,7 @@ genptable(PruneData *pd, int nthreads) | |||
| 179 | pd->count[0] = pd->n; | 180 | pd->count[0] = pd->n; |
| 180 | for (d = 0; d < 15 && pd->n < pd->coord->max; d++) { | 181 | for (d = 0; d < 15 && pd->n < pd->coord->max; d++) { |
| 181 | genptable_bfs(pd, d, nthreads, nchunks); | 182 | genptable_bfs(pd, d, nthreads, nchunks); |
| 182 | genptable_fixnasty(pd, d+1); | 183 | genptable_fixnasty(pd, d+1, nthreads); |
| 183 | fprintf(stderr, "Depth %d done, generated %" | 184 | fprintf(stderr, "Depth %d done, generated %" |
| 184 | PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", | 185 | PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", |
| 185 | d+1, pd->n - oldn, pd->n, pd->coord->max); | 186 | d+1, pd->n - oldn, pd->n, pd->coord->max); |
| @@ -256,30 +257,31 @@ genptable_compress(PruneData *pd) | |||
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | static void | 259 | static void |
| 259 | genptable_fixnasty(PruneData *pd, int d) | 260 | genptable_fixnasty(PruneData *pd, int d, int nthreads) |
| 260 | { | 261 | { |
| 261 | uint64_t i, ii; | 262 | int i; |
| 262 | int j, n; | 263 | pthread_t t[nthreads]; |
| 263 | Trans t, aux[NTRANS]; | 264 | ThreadDataGenpt td[nthreads]; |
| 265 | pthread_mutex_t *upmtx; | ||
| 264 | 266 | ||
| 265 | if (pd->coord->tfind == NULL) | 267 | if (pd->coord->tfind == NULL) |
| 266 | return; | 268 | return; |
| 267 | 269 | ||
| 268 | for (i = 0; i < pd->coord->max; i++) { | 270 | upmtx = malloc(sizeof(pthread_mutex_t)); |
| 269 | if (ptableval_index(pd, i) == d) { | 271 | pthread_mutex_init(upmtx, NULL); |
| 270 | if ((n = pd->coord->tfind(i, aux)) == 1) | 272 | for (i = 0; i < nthreads; i++) { |
| 271 | continue; | 273 | td[i].thid = i; |
| 272 | 274 | td[i].nthreads = nthreads; | |
| 273 | for (j = 0; j < n; j++) { | 275 | td[i].pd = pd; |
| 274 | t = aux[j]; | 276 | td[i].d = d; |
| 275 | ii = pd->coord->transform(t, i); | 277 | td[i].upmutex = upmtx; |
| 276 | if (ptableval_index(pd, ii) > d) { | 278 | pthread_create(&t[i], NULL, instance_fixnasty, &td[i]); |
| 277 | ptable_update_index(pd, ii, d); | ||
| 278 | pd->n++; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | } | ||
| 282 | } | 279 | } |
| 280 | |||
| 281 | for (i = 0; i < nthreads; i++) | ||
| 282 | pthread_join(t[i], NULL); | ||
| 283 | |||
| 284 | free(upmtx); | ||
| 283 | } | 285 | } |
| 284 | 286 | ||
| 285 | static void | 287 | static void |
| @@ -335,6 +337,51 @@ instance_bfs(void *arg) | |||
| 335 | } | 337 | } |
| 336 | } | 338 | } |
| 337 | } | 339 | } |
| 340 | |||
| 341 | pthread_mutex_lock(td->upmutex); | ||
| 342 | td->pd->n += updated; | ||
| 343 | pthread_mutex_unlock(td->upmutex); | ||
| 344 | |||
| 345 | return NULL; | ||
| 346 | } | ||
| 347 | |||
| 348 | static void * | ||
| 349 | instance_fixnasty(void *arg) | ||
| 350 | { | ||
| 351 | ThreadDataGenpt *td; | ||
| 352 | uint64_t i, ii, nb, blocksize, rmin, rmax, updated; | ||
| 353 | int j, n; | ||
| 354 | Trans t, aux[NTRANS]; | ||
| 355 | |||
| 356 | td = (ThreadDataGenpt *)arg; | ||
| 357 | nb = td->pd->coord->max / td->pd->coord->base->max; | ||
| 358 | blocksize = (uint64_t)((nb / td->nthreads) * td->pd->coord->base->max); | ||
| 359 | rmin = ((uint64_t)td->thid) * blocksize; | ||
| 360 | rmax = td->thid == td->nthreads - 1 ? | ||
| 361 | td->pd->coord->max : | ||
| 362 | ((uint64_t)td->thid + 1) * blocksize; | ||
| 363 | |||
| 364 | updated = 0; | ||
| 365 | for (i = rmin; i < rmax; i++) { | ||
| 366 | if (ptableval_index(td->pd, i) == td->d) { | ||
| 367 | if ((n = td->pd->coord->tfind(i, aux)) == 1) | ||
| 368 | continue; | ||
| 369 | |||
| 370 | for (j = 0; j < n; j++) { | ||
| 371 | if ((t = aux[j]) == uf) | ||
| 372 | continue; | ||
| 373 | ii = td->pd->coord->transform(t, i); | ||
| 374 | if (ii < rmin || ii >= rmax) | ||
| 375 | fprintf(stderr, | ||
| 376 | "Error: transformed out of bound!\n"); | ||
| 377 | if (ptableval_index(td->pd, ii) > td->d) { | ||
| 378 | ptable_update_index(td->pd, ii, td->d); | ||
| 379 | updated++; | ||
| 380 | } | ||
| 381 | } | ||
| 382 | } | ||
| 383 | } | ||
| 384 | |||
| 338 | pthread_mutex_lock(td->upmutex); | 385 | pthread_mutex_lock(td->upmutex); |
| 339 | td->pd->n += updated; | 386 | td->pd->n += updated; |
| 340 | pthread_mutex_unlock(td->upmutex); | 387 | pthread_mutex_unlock(td->upmutex); |
