If the number of tapes is greater than 0 (zero), and disk size is specifically set to 0, a tape-only sort is performed. In this mode, all sort work files are maintained on tape. It is advisable to use tapes in good condition when performing tape sorts. You can specify from 3 to 8 tapes for SORT to use as work files. The sorting method used for tape sorting is the polyphase merge/reverse technique.
Unlike a disk-only sort, where strings are written serially on the work file as they are formed, special string distributions and string-sequencing techniques are required for a tape sort. String distributions are based on a generalized Fibonacci number series. The string sequencing (ascending or descending) is specifically designed for reverse tape reads.
Tape-Only Stringing Phase
In the initial stringing phase, one work tape is designated as the first merge output tape and thus is not used during the stringing process. For example, in a 3-tape sort, strings are written to only two tapes. Strings are then dispersed to the stringing tapes in a special pattern until the current level in the distribution is satisfied. The distribution is transferred to the next level, and stringing continues. When the last input record is strung, the stringing phase is complete.
A special-string sequencing pattern is required by SORT because of the reverse tape-read technique used in the merging phase. The pattern is as follows:
-
Strings are written to an individual tape in alternating sequence—ascending, descending, ascending, and so on).
-
In an ascending sort operation, all tapes except the tape with the odd number of strings—that is, the last tape—begins with a descending string. The odd tape begins with an ascending string. In a descending sort, the sequence pattern is reversed.
The following example depicts the stringing phase of a 5-tape ascending sort:
TAPE 1 TAPE 2 TAPE 3 TAPE 4 ------ ------ ------ ------ 13 Strings D D D A Distribution is: 2,4,4,3 A A A D D D A A A D = DESCENDING STRING. A = ASCENDING STRING.
During the stringing phase, SORT moves cyclically on the tapes—that is, from tape 1 to tape n, where n represents an integer from 2 through 8—looking for a tape to string. If the distribution is satisfied on a given tape, SORT moves to the next tape. When the distribution is satisfied on all tapes, the Fibonacci distribution is transferred to the next level.
At the completion of the stringing phase, if the number of strings distributed is less than the desired Fibonacci distribution level, the tapes are padded with dummy strings to fill out the distribution. The dummy strings are recorded internally but are not physically written on the tapes.
Tape-Only Merging Phase
The merging phase of the tape sort operation uses the polyphase merge/reverse tape read technique. In the polyphase method, strings from working tapes are merged to a designated output tape until one of the tapes contains no more strings. This tape now becomes the output tape and is the end of a merge pass or level. The string totals on the remaining tapes now correspond to the next lower level in the distribution table. The merging operation continues until one final string can be written to the output file or procedure.