summaryrefslogtreecommitdiff
path: root/gl/lib/heap.c
AgeCommit message (Collapse)Author
2012-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2011-08-30build: heap.c: make possible gnulib candidate c89 compatiblePádraig Brady
* gl/lib/heap.c: Move declaration to the top of scope. Reported by Rob McMahon and Wolfgang Steinwender in relation to "Sun WorkShop 6 update 2 C 5.3 Patch 111679-12 2003/05/18" and "GCC 2.95.3" respectively.
2011-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2010-07-25sort: make struct heap privatePaul R. Eggert
* gl/lib/heap.c (struct heap): Move this here... * gl/lib/heap.h (struct heap): ... from here, as outside code no longer needs to access any of these members.
2010-07-25sort: use more-consistent style with constPaul R. Eggert
* src/sort.c (proctab_hasher, proctab_comparator, stream_open, xfopen): (open_temp, zaptemp, struct_month_cmp, begfield, limfield): (find_unit_order, human_numcompare, numcompare, general_numcompare): (count_tabs, keycompare, compare, compare_nodes, lock_node): (unlock_node, queue_destroy, queue_init, queue_insert, queue_pop): (write_unique, mergelines_node, check_insert, update_parent): (merge_loop, sortlines, struct thread_args, set_ordering): Prefer the style "T const" to "const T". * gl/lib/heap.h (struct heap, heap_alloc): Likewise. * gl/lib/heap.c (heap_default_compare, heapify_down, heapify_up): (heap_alloc): Likewise.
2010-07-14heap_alloc: avoid integer overflowJim Meyering
* gl/lib/heap.c (heap_alloc): Use xnmalloc rather than xmalloc, to avoid pathological overflow.
2010-07-13maint: heap.c: simplify dynamic allocationsPádraig Brady
* gl/lib/heap.c (heap_alloc): Use the fact that the xalloc routines will not return NULL. Also remove the redundant temporary variables. (heap_insert): From Jim Meyering, use x2nrealloc() which is simpler while handling overflow and increasing the size more efficiently. This reallocation is currently unused by coreutils in any case as it preallocates enough.
2010-07-13sort: parallelize internal sortChen Guo
This patch is by Gene Auyeung, Chris Dickens, Chen Guo, and Mike Nichols, based off of a patch by Paul Eggert, Glen Lenker, et. al., with a basic heap implementation based off of the GDSL heap, originally by Nicolas Darnis. The number of sorts done in parallel is limited to the number of available processors by default, or can be further restricted with the --parallel option. On a dual-die, 8 core Intel Xeon, results show sorting with 8 threads is almost 4 times faster than using a single thread. Timings when sorting a 96MB file: THREADS TIME (s) 1 5.10 2 2.87 4 1.75 8 1.31 Single threaded sorting has also been improved, especially for cheaper comparison operations: COMMAND BEFORE (s) AFTER (s) sort 8.822 8.716 sort -g 10.336 10.222 sort -n 3.077 2.961 LANG=C sort 2.169 2.066 * bootstrap.conf: Add heap, pthread. * coreutils.texi (sort): Describe the new --parallel option. * gl/lib/heap.c: New file. Very basic heap implementation. * gl/lib/heap.h: New file. * gl/modules/heap: New file. * src/Makefile.am: Add LIB_PTHREAD. * src/sort.c: Include heap.h, nproc.h, pthread.h. (MAX_MERGE): New macro. (SUBTHREAD_LINES_HEURISTIC, PARALLEL_OPTION): New constants. (MERGE_END, MERGE_ROOT): New constants. (struct merge_node): New struct. (struct merge_node_queue): New struct. (sortlines temp): Remove declaration. (usage, long_options, main): New option, --parallel. (specify_nthreads): New function. (mergelines): New signature, to emphasize the fact that the HI area must be part of the destination. All callers changed. (sequential_sort): New function, renamed from sortlines. Merge in the functionality of sortlines_temp. (compare_nodes): New function. (lock_node, unlock_node): New functions. (queue_destroy): New function. (queue_init): New function. (queue_insert): New function. (queue_pop): New function. (write_unique): New function. (mergelines_node): New function. (check_insert): New function. (update_parent): New function. (merge_loop): New function. (sortlines): Rewrite to support and use parallelism, with a new signature. All callers changed. (struct thread_args): New struct. (sortlines_thread): New function. (sortlines_temp): Remove. (sort): New argument NTHREADS. All uses changed. Output moved to mergelines_node. (main): disable threading if we are sorting at random. * tests/Makefile.am (TESTS): Add misc/sort-benchmark-random. * tests/misc/sort-benchmark-random: New file. Signed-off-by: Pádraig Brady <P@draigBrady.com>