X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fsorter%2Fgovern.c;h=619b351d4690db9d4d4ad124d1c1afc7c8f81943;hb=6d3660cc570e931744add16305f5bcdfb776da6b;hp=97ef04422b18d399b8b41e0e5691f95485ebf9b1;hpb=d3b0fd52103d46da06081ea01c98df78bf1854f0;p=libucw.git diff --git a/lib/sorter/govern.c b/lib/sorter/govern.c index 97ef0442..619b351d 100644 --- a/lib/sorter/govern.c +++ b/lib/sorter/govern.c @@ -48,9 +48,14 @@ sorter_presort(struct sort_context *ctx, struct sort_bucket *in, struct sort_buc sorter_alloc_buf(ctx); if (in->flags & SBF_CUSTOM_PRESORT) { + /* + * The trick with automatic joining, which we use for the normal presorter, + * is not necessary with the custom presorter, because the custom presorter + * is never called in the middle of the sorted data. + */ struct fastbuf *f = sbuck_write(out); out->runs++; - return ctx->custom_presort(f, ctx->big_buf, ctx->big_buf_size); // FIXME: out_only optimization? + return ctx->custom_presort(f, ctx->big_buf, ctx->big_buf_size); } return ctx->internal_sort(ctx, in, out, out_only); } @@ -278,6 +283,9 @@ sorter_multiway(struct sort_context *ctx, struct sort_bucket *b) static void sorter_radix(struct sort_context *ctx, struct sort_bucket *b, uns bits) { + // Add more bits if requested and allowed. + bits = MIN(bits + sorter_add_radix_bits, sorter_max_radix_bits); + uns nbuck = 1 << bits; SORT_XTRACE(2, "Running radix split on %s with hash %d bits of %d (expecting %s buckets)", F_BSIZE(b), bits, b->hash_bits, stk_fsize(sbuck_size(b) / nbuck)); @@ -325,7 +333,7 @@ sorter_decide(struct sort_context *ctx, struct sort_bucket *b) // How many bits of bucket size we have to reduce before it fits in the RAM? // (this is insanely large if the input size is unknown, but it serves our purpose) u64 insize = sbuck_size(b); - u64 mem = ctx->internal_estimate(ctx, b) * 0.8; // FIXME: Magical factor for various non-uniformities + u64 mem = ctx->internal_estimate(ctx, b) * 0.8; // Magical factor accounting for various non-uniformities uns bits = 0; while ((insize >> bits) > mem) bits++; @@ -391,6 +399,7 @@ sorter_run(struct sort_context *ctx) ctx->pool = mp_new(4096); clist_init(&ctx->bucket_list); sorter_prepare_buf(ctx); + asort_start_threads(0); // Create bucket containing the source struct sort_bucket *bin = sbuck_new(ctx); @@ -419,6 +428,7 @@ sorter_run(struct sort_context *ctx) while (bout = clist_head(&ctx->bucket_list), b = clist_next(&ctx->bucket_list, &bout->n)) sorter_decide(ctx, b); + asort_stop_threads(); sorter_free_buf(ctx); sbuck_write(bout); // Force empty bucket to a file SORT_XTRACE(2, "Final size: %s", F_BSIZE(bout));