#define ASORT_MIN_SHIFT 2
+#define ASORT_TRACE(x...) ASORT_XTRACE(1, x)
+#define ASORT_XTRACE(level, x...) do { if (sorter_trace_array >= level) msg(L_DEBUG, x); } while(0)
+
static void
asort_radix(struct asort_context *ctx, void *array, void *buffer, uns num_elts, uns hash_bits, uns swapped_output)
{
asort_threads_use_count++;
if (run && !asort_threads_ready)
{
- SORT_XTRACE(2, "Initializing thread pool (%d threads)", sorter_threads);
+ ASORT_TRACE("Initializing thread pool (%d threads)", sorter_threads);
asort_thread_pool.num_threads = sorter_threads;
worker_pool_init(&asort_thread_pool);
asort_threads_ready = 1;
ucwlib_lock();
if (!--asort_threads_use_count && asort_threads_ready)
{
- SORT_XTRACE(2, "Shutting down thread pool");
+ ASORT_TRACE("Shutting down thread pool");
worker_pool_cleanup(&asort_thread_pool);
asort_threads_ready = 0;
}
struct rs_work {
struct work w;
struct asort_context *ctx;
- void *in, *out;
+ void *array, *buffer; // Like asort_radix().
uns num_elts;
uns shift;
uns swap_output;
struct rs_work *w = (struct rs_work *) ww;
DBG("Thread %d: Counting %d items, shift=%d", thr->id, w->num_elts, w->shift);
- w->ctx->radix_count(w->in, w->num_elts, w->cnt, w->shift);
+ w->ctx->radix_count(w->array, w->num_elts, w->cnt, w->shift);
DBG("Thread %d: Counting done", thr->id);
}
struct rs_work *w = (struct rs_work *) ww;
DBG("Thread %d: Splitting %d items, shift=%d", thr->id, w->num_elts, w->shift);
- w->ctx->radix_split(w->in, w->out, w->num_elts, w->cnt, w->shift);
+ w->ctx->radix_split(w->array, w->buffer, w->num_elts, w->cnt, w->shift);
DBG("Thread %d: Splitting done", thr->id);
}
DBG("Thread %d: Finishing %d items, shift=%d", thr->id, w->num_elts, w->shift);
if (w->shift < ASORT_MIN_SHIFT || w->num_elts * w->ctx->elt_size < sorter_radix_threshold)
{
- w->ctx->quicksort(w->in, w->num_elts);
+ w->ctx->quicksort(w->array, w->num_elts);
if (w->swap_output)
- memcpy(w->out, w->in, w->num_elts * w->ctx->elt_size);
+ memcpy(w->buffer, w->array, w->num_elts * w->ctx->elt_size);
}
else
- asort_radix(w->ctx, w->in, w->out, w->num_elts, w->shift, w->swap_output);
+ asort_radix(w->ctx, w->array, w->buffer, w->num_elts, w->shift, w->swap_output);
if (thr)
DBG("Thread %d: Finishing done", thr->id);
}
w->w.priority = 0;
w->w.go = rs_count;
w->ctx = ctx;
- w->in = iptr;
- w->out = buffer;
+ w->array = iptr;
+ w->buffer = buffer;
w->num_elts = blksize;
if (i == sorter_threads-1)
w->num_elts += num_elts % sorter_threads;
w->w.priority = 0;
w->w.go = rs_finish;
w->ctx = ctx;
- w->in = buffer;
- w->out = array;
+ w->array = buffer;
+ w->buffer = array;
w->num_elts = n;
w->shift = shift;
w->swap_output = !swapped_output;
void
asort_run(struct asort_context *ctx)
{
- SORT_XTRACE(10, "Array-sorting %d items per %d bytes, hash_bits=%d", ctx->num_elts, ctx->elt_size, ctx->hash_bits);
+ ASORT_TRACE("Array-sorting %d items per %d bytes, hash_bits=%d", ctx->num_elts, ctx->elt_size, ctx->hash_bits);
uns allow_threads UNUSED = (sorter_threads > 1 &&
ctx->num_elts * ctx->elt_size >= sorter_thread_threshold &&
!(sorter_debug & SORT_DEBUG_ASORT_NO_THREADS));
#ifdef CONFIG_UCW_THREADS
if (allow_threads)
{
- SORT_XTRACE(12, "Decided to use parallel quicksort");
+ ASORT_XTRACE(2, "Decided to use parallel quicksort");
threaded_quicksort(ctx);
return;
}
#endif
- SORT_XTRACE(12, "Decided to use sequential quicksort");
+ ASORT_XTRACE(2, "Decided to use sequential quicksort");
ctx->quicksort(ctx->array, ctx->num_elts);
}
else
#ifdef CONFIG_UCW_THREADS
if (allow_threads)
{
- SORT_XTRACE(12, "Decided to use parallel radix-sort (swap=%d)", swap);
+ ASORT_XTRACE(2, "Decided to use parallel radix-sort (swap=%d)", swap);
threaded_radixsort(ctx, swap);
return;
}
#endif
- SORT_XTRACE(12, "Decided to use sequential radix-sort (swap=%d)", swap);
+ ASORT_XTRACE(2, "Decided to use sequential radix-sort (swap=%d)", swap);
asort_radix(ctx, ctx->array, ctx->buffer, ctx->num_elts, ctx->hash_bits, swap);
if (swap)
ctx->array = ctx->buffer;
}
- SORT_XTRACE(11, "Array-sort finished");
+ ASORT_XTRACE(2, "Array-sort finished");
}