- Change --nthreads parameter to --parallel for GNU compatibility
- Change default sort method to mergesort, which has a better worst case performance than qsort Submitted by: Oleg Moskalenko <oleg.moskalenko@citrix.com>
This commit is contained in:
parent
6d38f252e7
commit
58344b5c4d
@ -1297,7 +1297,7 @@ sort_list_to_file(struct sort_list *list, const char *outfile)
|
||||
}
|
||||
|
||||
if (sort_opts_vals.sort_method == SORT_DEFAULT)
|
||||
sort_opts_vals.sort_method = SORT_QSORT;
|
||||
sort_opts_vals.sort_method = DEFAULT_SORT_ALGORITHM;
|
||||
|
||||
if (debug_sort)
|
||||
printf("sort_method=%s\n",
|
||||
@ -1314,9 +1314,12 @@ sort_list_to_file(struct sort_list *list, const char *outfile)
|
||||
case SORT_HEAPSORT:
|
||||
mt_sort(list, heapsort, outfile);
|
||||
break;
|
||||
default:
|
||||
case SORT_QSORT:
|
||||
mt_sort(list, sort_qsort, outfile);
|
||||
break;
|
||||
default:
|
||||
mt_sort(list, DEFAULT_SORT_FUNC, outfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,9 @@
|
||||
#define SORT_HEAPSORT 3
|
||||
#define SORT_RADIXSORT 4
|
||||
|
||||
#define DEFAULT_SORT_ALGORITHM SORT_HEAPSORT
|
||||
#define DEFAULT_SORT_FUNC heapsort
|
||||
|
||||
/*
|
||||
* List of data to be sorted.
|
||||
*/
|
||||
|
@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "coll.h"
|
||||
#include "radixsort.h"
|
||||
|
||||
#define DEFAULT_SORT_FUNC_RADIXSORT mergesort
|
||||
|
||||
#define TINY_NODE(sl) ((sl)->tosort_num < 65)
|
||||
#define SMALL_NODE(sl) ((sl)->tosort_num < 5)
|
||||
|
||||
@ -349,7 +351,7 @@ run_sort_level_next(struct sort_level *sl)
|
||||
/* NOTREACHED */
|
||||
err(2, "Radix sort error 3");
|
||||
} else
|
||||
qsort(sl->leaves, sl->leaves_num,
|
||||
DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) func);
|
||||
|
||||
@ -389,12 +391,12 @@ run_sort_level_next(struct sort_level *sl)
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) list_coll);
|
||||
} else {
|
||||
qsort(sl->leaves, sl->leaves_num,
|
||||
DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) list_coll);
|
||||
}
|
||||
} else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) {
|
||||
qsort(sl->leaves, sl->leaves_num,
|
||||
DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) list_coll_by_str_only);
|
||||
}
|
||||
@ -541,12 +543,12 @@ run_top_sort_level(struct sort_level *sl)
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) list_coll);
|
||||
} else {
|
||||
qsort(sl->leaves, sl->leaves_num,
|
||||
DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) list_coll);
|
||||
}
|
||||
} else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) {
|
||||
qsort(sl->leaves, sl->leaves_num,
|
||||
DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
|
||||
sizeof(struct sort_list_item *),
|
||||
(int(*)(const void *, const void *)) list_coll_by_str_only);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
.\"
|
||||
.\" @(#)sort.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd May 25, 2012
|
||||
.Dd July 3, 2012
|
||||
.Dt SORT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -329,7 +329,7 @@ is used.
|
||||
.It Fl Fl debug
|
||||
Print some extra information about the sorting process to the
|
||||
standard output.
|
||||
%%THREADS%%.It Fl Fl nthreads
|
||||
%%THREADS%%.It Fl Fl parallel
|
||||
%%THREADS%%Set the maximum number of execution threads.
|
||||
%%THREADS%%Default number equals to the number of CPUs.
|
||||
.It Fl Fl files0-from Ns = Ns Ar filename
|
||||
|
@ -91,7 +91,7 @@ const char *nlsstr[] = { "",
|
||||
"[--heapsort] [--mergesort] [--radixsort] [--qsort] "
|
||||
"[--mmap] "
|
||||
#if defined(SORT_THREADS)
|
||||
"[--nthreads thread_no] "
|
||||
"[--parallel thread_no] "
|
||||
#endif
|
||||
"[--human-numeric-sort] "
|
||||
"[--version-sort] [--random-sort [--random-source file]] "
|
||||
@ -132,7 +132,7 @@ enum
|
||||
VERSION_OPT,
|
||||
DEBUG_OPT,
|
||||
#if defined(SORT_THREADS)
|
||||
NTHREADS_OPT,
|
||||
PARALLEL_OPT,
|
||||
#endif
|
||||
RANDOMSOURCE_OPT,
|
||||
COMPRESSPROGRAM_OPT,
|
||||
@ -171,7 +171,7 @@ struct option long_options[] = {
|
||||
{ "numeric-sort", no_argument, NULL, 'n' },
|
||||
{ "output", required_argument, NULL, 'o' },
|
||||
#if defined(SORT_THREADS)
|
||||
{ "nthreads", required_argument, NULL, NTHREADS_OPT },
|
||||
{ "parallel", required_argument, NULL, PARALLEL_OPT },
|
||||
#endif
|
||||
{ "qsort", no_argument, NULL, QSORT_OPT },
|
||||
{ "radixsort", no_argument, NULL, RADIXSORT_OPT },
|
||||
@ -1119,7 +1119,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
#if defined(SORT_THREADS)
|
||||
case NTHREADS_OPT:
|
||||
case PARALLEL_OPT:
|
||||
nthreads = (size_t)(atoi(optarg));
|
||||
if (nthreads < 1)
|
||||
nthreads = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user