WiscSort / EMS / pmemSort.cpp
pmemSort.cpp
Raw
#include "record_pmem_direct.h"
#include <chrono>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <algorithm>
#include <sys/mman.h>
#include "timer.h"
#include <string>
#include "config.h"

#include "ips4o/include/ips4o.hpp"

using namespace std;
struct Config conf;

int main(int argc, char **argv)
{
    Timer timer;
    string input_file = argv[1];
    int fd = open(input_file.c_str(), O_RDWR | O_DIRECT);
    if (fd < 0)
    {
        printf("Couldn't open input file %s: %s\n", input_file.c_str(), strerror(errno));
        exit(1);
    }
    struct stat st;
    stat(input_file.c_str(), &st);
    record_t *mapped_buffer = (record_t *)mmap(NULL, st.st_size, PROT_READ | PROT_WRITE,
                                               MAP_PRIVATE | MAP_POPULATE, fd, 0);
    if (mapped_buffer == MAP_FAILED)
    {
        printf("Failed to mmap read file of size %lu: %s\n",
               st.st_size, strerror(errno));
        return -1;
    }

    conf.sort_thrds = 20;

    timer.start("SORT");
    ips4o::parallel::sort(mapped_buffer, mapped_buffer + st.st_size / 100, std::less<>{});
    timer.end("SORT");

    printf("Sort time: %f\n", timer.get_overall_time("SORT"));
}