Commit 1d33a6ec authored by Illia Kolesnik's avatar Illia Kolesnik
Browse files

Added table generator

parent fbe4a4e7
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -306,6 +306,9 @@ main( Index argc, char const* argv[] )
   vector< Index > indecies = readIndecies( benchDir );
   string distribution = readDistribution( benchDir );

   cerr << "Refines " << refineCoords.size() << " searches " << searchCoords.size() << " indecies " << indecies.size()
        << " distribution " << distribution << endl;

   // Create benchmark objects
   unique_ptr< AbsOctree > linear( new LinearOcreee() );
   unique_ptr< AbsOctree > classic( new ClassicOctree() );
@@ -321,7 +324,7 @@ main( Index argc, char const* argv[] )

   // Print results
   CSVWriter writer( refineCoords.size(), distribution );
   cerr << "OPERATION;REFINES;SIZE;DISTRIBUTION;LINEAR;CLASSIC;SPEEDUP\n";
   // cerr << "OPERATION;REFINES;SIZE;DISTRIBUTION;LINEAR;CLASSIC;SPEEDUP\n";
   writer.printRow( OP_REFINEMENT, refineCoords.size(), resRef );
   writer.printRow( OP_SEARCH, searchCoords.size(), resSearch );
   writer.printRow( OP_SEARCH_ALL, searchCoords.size(), resSearchAll );
+1 −1
Original line number Diff line number Diff line
@@ -14,4 +14,4 @@ cuckoo:
debug:
	g++ Benchmark.cpp $(INCLUDE) $(COMMON) -g -O0
clean:
	rm -r *.o *.vtk *.vtu a.out* *.txt *bench *.log
 No newline at end of file
	rm -r *.o *.vtk *.vtu a.out* *.txt *bench *.log *.csv
 No newline at end of file
+102 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3

import pandas as pd
import sys
import matplotlib.pyplot as plt
import os
import shutil

# Names of operations
OP_REFINEMENT = "refinement"
OP_SEARCH = "search"
OP_SEARCH_ALL = "search_all"
OP_SEARCH_NOT_REFINED = "search_not_refined"
OP_SEARCH_ALL_NOT_REFINED = "search_all_not_refined"


if len(sys.argv) != 3:
    print("Usage: python generate_docs.py <input_csv> <output_dir>")
    exit(1)

input_csv = sys.argv[1]
output_dir = sys.argv[2]

TITLE_FORMAT = "{operation}, {refine} refines, {distribution} distribution"
DIRNAME_FORMAT = "{distribution}_{refine}"

# If create dir doesn't exist, create it
if not os.path.exists(output_dir):
    os.makedirs(output_dir)

# CSV columns:
# OPERATION;REFINES;SIZE;DISTRIBUTION;LINEAR;CLASSIC;SPEEDUP
df = pd.read_csv(input_csv, sep=";")

# Get unique distributions
distributions = df["DISTRIBUTION"].unique()

# Get unique refines
refines = df["REFINES"].unique()

# Get unique operations
operations = df["OPERATION"].unique()

# Create docs
for distribution in distributions:
    for refine in refines:
        # If directory exists, recreate it, even if it's empty
        dirname = DIRNAME_FORMAT.format(
            refine=refine, distribution=distribution
        )
        result_dir = output_dir + "/" + dirname
        if os.path.exists(result_dir):
            shutil.rmtree(result_dir)
        os.makedirs(result_dir)

        for operation in operations:
            # Filter by distribution, refine, operation
            filtered = df.loc[df["DISTRIBUTION"] == distribution]
            filtered = filtered.loc[filtered["REFINES"] == refine]
            filtered = filtered.loc[filtered["OPERATION"] == operation]

            title = TITLE_FORMAT.format(
                operation=operation, refine=refine, distribution=distribution
            )

            # Create dataframes
            all_df = filtered[["SIZE", "LINEAR", "CLASSIC", "SPEEDUP"]]
            times_df = filtered[["SIZE", "LINEAR", "CLASSIC"]]
            speedup_df = filtered[["SIZE", "SPEEDUP"]]
            # Sort by size
            times_df = times_df.sort_values(by=["SIZE"])
            speedup_df = speedup_df.sort_values(by=["SIZE"])

            # Create plots, save as pdf
            # Times
            times_df.plot(x="SIZE", y=["LINEAR", "CLASSIC"], marker="o")
            plt.xlabel("Size")
            plt.ylabel("Time (s)")
            plt.title(title)
            plt.legend(["Linear", "Classic"])
            plt.savefig(f"{result_dir}/{operation}_times.pdf")
            plt.close()

            # Speedup, show 2 lines: speedup and 1
            speedup_df.plot(x="SIZE", y=["SPEEDUP"], marker="o")
            # Add line y=1
            plt.plot(
                [speedup_df["SIZE"].min(), speedup_df["SIZE"].max()],
                [1, 1],
                color="red",
                linestyle="dashed",
            )
            plt.xlabel("Size")
            plt.ylabel("Speedup, times")
            plt.title(title)
            plt.legend(["Speedup, linear/classic"])
            plt.savefig(f"{result_dir}/{operation}_speedup.pdf")
            plt.close()

            # Save dataframe as table to file
            with open(f"{result_dir}/{operation}_times.txt", "w") as f:
                f.write(all_df.to_string(index=False))
+24 −6
Original line number Diff line number Diff line
#!/bin/bash

RESULT_FILE="results.csv"

DESIRED_DISTRIBUTIONS=("unif" "normal" "exp")
# DESIRED_REFINES=(10000 20000 50000 100000 200000 500000 1000000 2000000 5000000 10000000)
# DESIRED_SEARCHES=(10000 20000 50000 100000 200000 500000 1000000 2000000 5000000 10000000 20000000 50000000 100000000)
# DESIRED_DISTRIBUTIONS=("unif")
DESIRED_REFINES=(10000)
DESIRED_SEARCHES=(20000)
DESIRED_SEARCHES=(20000 30000 50000 100000 )
TMP_DIR="bench"

# Stop on error
set -e

USAGE="Usage: ./run_benchmarks.sh <bin> <generator> <result_csv>"
if [ $# -ne 3 ]; then
    echo $USAGE
    exit 1
fi

BIN="$1"
GENERATOR="$2"
RESULT_FILE="$3"


run_benchmark() {
    local distribution="$1"
    local refine="$2"
    local search="$3"
    
    rm -r "bench"
    ./Generator.py $refine $search $distribution bench
    ./a.out bench >> $RESULT_FILE
    # Check if bench dir exists, remove if it does
    if [ -d "bench" ]; then
        rm -rf bench
    fi

    ./$GENERATOR $refine $search $distribution $TMP_DIR
    ./$BIN $TMP_DIR >> $RESULT_FILE
}

echo "OPERATION;REFINES;SIZE;DISTRIBUTION;LINEAR;CLASSIC;SPEEDUP" > $RESULT_FILE