aboutsummaryrefslogtreecommitdiff
path: root/src/pruning.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pruning.c')
-rw-r--r--src/pruning.c89
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 @@
6static int findchunk(PruneData *pd, int nchunks, uint64_t i); 6static int findchunk(PruneData *pd, int nchunks, uint64_t i);
7static void genptable_bfs(PruneData *pd, int d, int nt, int nc); 7static void genptable_bfs(PruneData *pd, int d, int nt, int nc);
8static void genptable_compress(PruneData *pd); 8static void genptable_compress(PruneData *pd);
9static void genptable_fixnasty(PruneData *pd, int d); 9static void genptable_fixnasty(PruneData *pd, int d, int nthreads);
10static void genptable_setbase(PruneData *pd); 10static void genptable_setbase(PruneData *pd);
11static void * instance_bfs(void *arg); 11static void * instance_bfs(void *arg);
12static void * instance_fixnasty(void *arg);
12static void ptable_update(PruneData *pd, Cube cube, int m); 13static void ptable_update(PruneData *pd, Cube cube, int m);
13static void ptable_update_index(PruneData *pd, uint64_t ind, int m); 14static void ptable_update_index(PruneData *pd, uint64_t ind, int m);
14static int ptableval_index(PruneData *pd, uint64_t ind); 15static 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
258static void 259static void
259genptable_fixnasty(PruneData *pd, int d) 260genptable_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
285static void 287static 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
348static void *
349instance_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);

Generated with cgit - Back to sebastiano.tronto.net