FastSort Manual

Sorting in Parallel
FastSort Manual429834-003
6-15
Parallel Sorting From C Programs
Parallel Sorting From C Programs
Example 6-1 shows a C program that calls FastSort system procedures to perform a
parallel sort run.
Example 6-1. C Example of a Parallel Sort Run (page 1 of 5)
#pragma sql wheneverlist
#pragma symbols
#pragma inspect
#pragma runnable
#pragma nolist
/*-------------------------------------------------------------*/
/* FastSort Parallel Sort Run */
/*-------------------------------------------------------------*/
/* This program uses subsorts to sort an input file. Overflow */
/* scratch volumes are specified in SORTBUILDPARM. Error */
/* handling and displaying of statistics are stubbed out. */
/*-------------------------------------------------------------*/
/* External declarations */
/*-------------------------------------------------------------*/
#include <stdioh>
#include <stdlibh>
#include <stringh>
#include <sqlh>
#include <talh>
#include <cextdecs>
#pragma list
#define MAXSUBSORTS 3 /* max number of subsorts */
#define MAXSCRATCHVOLS 4 /* max number of scratch volumes */
char home_term_name[48]; /* terminal name */
short home_term_filenum; /* file number */
short home_term_len; /* actual len of hometerm name */
short home_term_maxlen = 48;/* max len of hometerm name */
short error_detail; /* output from process_getinfo_ */
/*-------------------------------------------------------------*/
/* FastSort control and flags information. */
/*-------------------------------------------------------------*/
_lowmem short ctlblk[200]; /* control block for sort interface*/
_lowmem short key_array[4]; /* SORTMERGESTART key field defns */
short sflag1 = 1; /* use 22-word SORTMERGESTATISTICS array */
short flags = 512; /* use expanded process_start structure */
/* same as setting flags.<6> in TAL */
/*-------------------------------------------------------------*/
/* FastSort error and statistics variables. */
/*-------------------------------------------------------------*/
short error; /* error return parameter */
_lowmem short error_buf[20], /* error message buffer */
error_source[20], /* error related info */
sub_index, /* subsort that caused error*/
sub_cpu_pin; /* CPU,PIN of this subsort */
_lowmem long error_code[40]; /* Fastsort & system error codes */
struct sortstats_template {
short maxrecordsize;
short bufferpages;
long records;
long elapsedtime;
long compares;
long scratchseeks;
long iowaittime;
long scratchfileeof;
long initialruns;
short firstmergeorder;
short mergeorder;
short intermediatepasses;
long numberofduplicates;
} _lowmem sortstats;