main.cpp 3.77 KB
Newer Older
Ernst Naschenweng's avatar
Ernst Naschenweng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/*
 * Author: Ernst Naschenweng
 * Bachelor's Thesis in Scientific Computing
 * University of Vienna
 */

#include <iostream>
#include "fw.h"

std::string wrapBoolToTextOutput(bool verifyResult) {
    if(verifyResult)
        return "OK";

    return "ERROR";
}

// CAREFUL! command line arguments are not sanity checked or sanitized
// argv[1] = matrix size n
// argv[2] = how often to loop the benchmark
// argv[3] = blocking factor
// argv[4] = number of threads for omp
// example call: ./a.out 512 5 9 64
int main(int argc, char* argv[]) {
    int n = std::atoi(argv[1]);
    int runs = std::atoi(argv[2]);
    bool use_avx512 = true;
    double minWeight = 2;
    double maxWeight = 70;
    unsigned short density = 80;
    unsigned int seed = 3729;
    Matrix* data = new Matrix(n);

    for(int r = 0; r < runs; ++r) {
        std::cout << "matrix size: " << n << std::endl;
        std::cout << "run: " << r+1 << std::endl;

        // Boost reference implementation
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->boost_FW() << std::endl;

        // backup boost result for verification
        double* boost = new double[n*n]();
        data->copyData(boost);

        // Single threaded, unoptimized Floyd-Warshall
        data->generateData(minWeight, maxWeight, density, seed);
        std::cout << data->simple_FW();
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Single threaded, FUR-optimized Floyd-Warshall
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->simple_FW_FUR();
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Single threaded, unoptimized, AVX Floyd-Warshall
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->simple_FW_AVX(use_avx512);
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        int blockFactor = std::atoi(argv[3]);
        int threads = std::atoi(argv[4]);

        // Blocked Floyd-Warshall
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->blocked_FW(blockFactor);
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Blocked Floyd-Warshall FUR
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->blocked_FW_FUR(blockFactor);
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Blocked Floyd-Warshall AVX
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->blocked_FW_AVX(blockFactor, use_avx512);
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Blocked Floyd-Warshall AVX OMP
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->blocked_FW_AVX_OMP(blockFactor, threads, use_avx512);
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Single threaded, ZUR-optimized Floyd-Warshall
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->simple_FW_ZUR();
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        // Blocked Floyd-Warshall ZUR
        data->generateData(minWeight, maxWeight, density, seed);
        std:: cout << data->blocked_FW_ZUR(blockFactor);
        std::cout << " - verify: " << wrapBoolToTextOutput(data->verifyAgainstBoost(boost)) << std::endl;

        std::cout << "-end run " << r+1 << "-" << std::endl;
    }

    return 0;
}