The routine may be called by the names m01caf or nagf_sort_realvec_sort.
m01caf is based on Singleton's implementation of the ‘median-of-three’ Quicksort algorithm (see Singleton (1969)), but with two additional modifications. First, small subfiles are sorted by an insertion sort on a separate final pass (see Sedgewick (1978)). Second, if a subfile is partitioned into two very unbalanced subfiles, the larger of them is flagged for special treatment: before it is partitioned, its end points are swapped with two random points within it; this makes the worst case behaviour extremely unlikely.
Sedgewick R (1978) Implementing Quicksort programs Comm. ACM21 847–857
Singleton R C (1969) An efficient algorithm for sorting with minimal storage: Algorithm 347 Comm. ACM12 185–187
1: – Real (Kind=nag_wp) arrayInput/Output
On entry: elements
of rv must contain real values to be sorted.
On exit: these values are rearranged into sorted order.
2: – IntegerInput
On entry: the index of the first element of rv to be sorted.
3: – IntegerInput
On entry: the index of the last element of rv to be sorted.
4: – Character(1)Input
On entry: if , the values will be sorted into ascending (i.e., nondecreasing) order.
If , into descending order.
5: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
m01caf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
The average time taken by m01caf is approximately proportional to , where . The worst case time is proportional to but this is extremely unlikely to occur.
This example reads a list of real numbers and sorts them into ascending order.