WiscSort / wiscSort / Gamma / test.cc
test.cc
Raw
#include <string>
#include "config.h"
#include "ext_sort.h"
#include <getopt.h>

void parseCmdline(int, char **);

struct Config conf;

int main(int argc, char **argv)
{
    parseCmdline(argc, argv);

    ExtSort sorter(conf.output_dir);
    sorter.Sort(conf.files);
}

void print_help_message(const char *progname)
{
    /* take only the last portion of the path */
    const char *basename = strrchr(progname, '/');
    basename = basename ? basename + 1 : progname;

    printf("WiscSort usage: %s [OPTION]\n", basename);
    printf("\t -h, --help\n"
           "\t Print this help and exit.\n"
           "\t Change the RECORD size in config.h\n"
           "\t If you need help with workload generation check Gensort.\n");
    printf("\t -i, --input[=FILENAMES]\n"
           "\t List of unsorted files.\n");
    printf("\t -o, --output_dir[=OUTPUTDIR]\n"
           "\t Output dir (can be different mount points)\n"
           "\t The output file is saved as 'sorted'.\n");
    printf("\t -b, --block\n"
           "\t Read/write block size used for the device.\n");
    printf("\t -m, --mode\n"
           "\t The concurrency modes:\n"
           "\t\t 0 -> Staged\n"
           "\t\t 1 -> RSW\n"
           "\t\t 2 -> Piped\n");
    printf("\t -q, --write-buffer\n"
           "\t Write buffer size.\n");
    printf("\t -r, --read-threads\n"
           "\t Number of reader threads. It must evenly divide read buffer.\n"
           "\t Per thread chunk size should evenly divide the block size specified.\n");
    printf("\t -s, --sort-threads\n"
           "\t Number of sorter threads.\n");
    printf("\t -w, --write-threads\n"
           "\t Number of writer threads. It must evenly divide write buffer.\n");
}

// Parse cmdline and init the config
void parseCmdline(int argc, char **argv)
{

    static struct option long_options[] = {
        {"input", required_argument, 0, 'i'},
        {"output_dir", required_argument, 0, 'o'},
        {"block", required_argument, 0, 'b'},
        {"mode", required_argument, 0, 'm'},
        {"write-buffer", required_argument, 0, 'q'},
        {"read-threads", required_argument, 0, 'r'},
        {"sort-threads", required_argument, 0, 's'},
        {"write-threads", required_argument, 0, 'w'},
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}};
    // read the args
    int c, option_index = 0;
    while (1)
    {
        c = getopt_long(argc, argv, "i:o:b:m:q:r:s:w:h",
                        long_options, &option_index);

        // is end of the option
        if (c == -1)
            break;

        switch (c)
        {
        case 0:
            break;
        case 'i':
            conf.files.push_back(optarg);
            break;
        case 'o':
            conf.output_dir = optarg;
            break;
        // case 'k':
        //     conf.key_size = atoi(optarg);
        //     break;
        // case 'v':
        //     conf.value_size = atoi(optarg);
        //     break;
        case 'b':
            conf.block_size = atoi(optarg);
            break;
        case 'm':
            conf.mode = atoi(optarg);
            break;
        case 'q':
            conf.write_buffer_size = GB((size_t)(atoi(optarg)));
            //conf.write_buffer_size = 10240000000;
            // conf.write_buffer_size = 4096000000;
            // conf.write_buffer_size = 20480000000;
            break;
        case 'r':
            conf.read_thrds = atoi(optarg);
            break;
        case 's':
            conf.sort_thrds = atoi(optarg);
            break;
        case 'w':
            conf.write_thrds = atoi(optarg);
            break;
        case 'h':
            print_help_message(argv[0]);
            _exit(0);
        default:
            break;
        }
    }
    // fill the rest of the struct before returning
    conf.record_size = RECORD_SIZE;
    conf.idx_record_size = IDX_RECORD_SIZE;
    conf.recs_per_blk = conf.block_size / conf.record_size;
}