From 4ba02e30def099f0837fcf45e9483637505cf62a Mon Sep 17 00:00:00 2001 From: nebmit <76664673+nebmit@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:52:56 +0100 Subject: [PATCH] test: added large scale test --- julia/tests/cpp_bench/BTCS_1024_1000_100.cpp | 45 +++++++++++++++++++ ...S_450_670_100.cpp => BTCS_450_670_750.cpp} | 2 +- julia/tests/julia_bench/BTCS_1024_1000_100.jl | 41 +++++++++++++++++ ...TCS_450_670_100.jl => BTCS_450_670_750.jl} | 2 +- julia/tests/test.py | 27 +++++++---- 5 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 julia/tests/cpp_bench/BTCS_1024_1000_100.cpp rename julia/tests/cpp_bench/{BTCS_450_670_100.cpp => BTCS_450_670_750.cpp} (97%) create mode 100644 julia/tests/julia_bench/BTCS_1024_1000_100.jl rename julia/tests/julia_bench/{BTCS_450_670_100.jl => BTCS_450_670_750.jl} (95%) diff --git a/julia/tests/cpp_bench/BTCS_1024_1000_100.cpp b/julia/tests/cpp_bench/BTCS_1024_1000_100.cpp new file mode 100644 index 0000000..db5d119 --- /dev/null +++ b/julia/tests/cpp_bench/BTCS_1024_1000_100.cpp @@ -0,0 +1,45 @@ +#include +#include + +using namespace Eigen; +using namespace tug; + +int main(int argc, char *argv[]) +{ + // **** GRID **** + int rows = 1024; + int cols = 1000; + Grid64 grid(rows, cols); + + MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0.5); + concentrations(10, 10) = 15000; + concentrations(1014, 990) = 7500; + concentrations(10, 990) = 7500; + concentrations(1014, 10) = 7500; + grid.setConcentrations(concentrations); + + MatrixXd alphax = MatrixXd::Constant(rows, cols, 1.25); + MatrixXd alphay = MatrixXd::Constant(rows, cols, 1.1); + alphax.block(0, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.5); + alphax.block(100, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.8); + alphay.block(0, 0, rows, 200) = MatrixXd::Constant(rows, 200, 0.6); + alphay.block(0, 200, rows, 200) = MatrixXd::Constant(rows, 200, 0.9); + grid.setAlpha(alphax, alphay); + + // **** BOUNDARY **** + Boundary bc = Boundary(grid); + bc.setBoundarySideClosed(BC_SIDE_LEFT); + bc.setBoundarySideClosed(BC_SIDE_RIGHT); + bc.setBoundarySideClosed(BC_SIDE_TOP); + bc.setBoundarySideClosed(BC_SIDE_BOTTOM); + + // **** SIMULATION **** + Simulation simulation = Simulation(grid, bc); + simulation.setTimestep(0.01); + simulation.setIterations(100); + simulation.setOutputCSV(CSV_OUTPUT_VERBOSE); + simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); + + // **** RUN SIMULATION **** + simulation.run(); +} diff --git a/julia/tests/cpp_bench/BTCS_450_670_100.cpp b/julia/tests/cpp_bench/BTCS_450_670_750.cpp similarity index 97% rename from julia/tests/cpp_bench/BTCS_450_670_100.cpp rename to julia/tests/cpp_bench/BTCS_450_670_750.cpp index 963bd21..a3e8696 100644 --- a/julia/tests/cpp_bench/BTCS_450_670_100.cpp +++ b/julia/tests/cpp_bench/BTCS_450_670_750.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) // **** SIMULATION **** Simulation simulation = Simulation(grid, bc); simulation.setTimestep(0.2); - simulation.setIterations(100); + simulation.setIterations(750); simulation.setOutputCSV(CSV_OUTPUT_VERBOSE); simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); diff --git a/julia/tests/julia_bench/BTCS_1024_1000_100.jl b/julia/tests/julia_bench/BTCS_1024_1000_100.jl new file mode 100644 index 0000000..d721cdc --- /dev/null +++ b/julia/tests/julia_bench/BTCS_1024_1000_100.jl @@ -0,0 +1,41 @@ +include("../../tug/Simulation.jl") + +function main() + # **** GRID **** + rows::Int = 1024 + cols::Int = 1000 + + alphaX = fill(1.25, rows, cols) + alphaY = fill(1.1, rows, cols) + alphaX[1:100, :] .= 0.5 + alphaX[101:200, :] .= 0.8 + alphaY[:, 1:200] .= 0.6 + alphaY[:, 201:400] .= 0.9 + grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) + + concentrations = fill(0.5, rows, cols) + concentrations[11, 11] = 15000 + concentrations[1015, 991] = 7500 + concentrations[11, 991] = 7500 + concentrations[1015, 11] = 7500 + setConcentrations!(grid, concentrations) + + # **** BOUNDARY **** + bc::Boundary = Boundary(grid) + setBoundarySideClosed!(bc, LEFT) + setBoundarySideClosed!(bc, RIGHT) + setBoundarySideClosed!(bc, TOP) + setBoundarySideClosed!(bc, BOTTOM) + + # **** SIMULATION **** + simulation::Simulation = Simulation(grid, bc) + simulation = setTimestep(simulation, 0.01) + simulation = setIterations(simulation, 100) + simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) + simulation = setOutputCSV(simulation, CSV_OUPUT_VERBOSE) + + # **** RUN SIMULATION **** + run(simulation) +end + +main() diff --git a/julia/tests/julia_bench/BTCS_450_670_100.jl b/julia/tests/julia_bench/BTCS_450_670_750.jl similarity index 95% rename from julia/tests/julia_bench/BTCS_450_670_100.jl rename to julia/tests/julia_bench/BTCS_450_670_750.jl index eec3f37..7a1082e 100644 --- a/julia/tests/julia_bench/BTCS_450_670_100.jl +++ b/julia/tests/julia_bench/BTCS_450_670_750.jl @@ -31,7 +31,7 @@ function main() # **** SIMULATION **** simulation::Simulation = Simulation(grid, bc) simulation = setTimestep(simulation, 0.2) - simulation = setIterations(simulation, 100) + simulation = setIterations(simulation, 750) simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) simulation = setOutputCSV(simulation, CSV_OUPUT_VERBOSE) diff --git a/julia/tests/test.py b/julia/tests/test.py index 9241072..9ca6a35 100644 --- a/julia/tests/test.py +++ b/julia/tests/test.py @@ -1,9 +1,11 @@ -import os -import subprocess import argparse -from compare_csv import compare_csv_files +import os +import statistics +import subprocess import time +from compare_csv import compare_csv_files + # ANSI color codes RED = '\033[0;31m' GREEN = '\033[0;32m' @@ -38,12 +40,19 @@ def format_difference(diff): return '0'.rjust(9) def run_benchmark(command, runs): - total_time = 0 + times = [] for _ in range(runs): - start_time = time.time() + start_time = time.perf_counter() subprocess.run(command) - total_time += time.time() - start_time - return total_time / runs + elapsed = time.perf_counter() - start_time + times.append(elapsed) + + avg_time = sum(times) / len(times) + min_time = min(times) + max_time = max(times) + std_dev = statistics.stdev(times) if len(times) > 1 else 0 + + return avg_time, min_time, max_time, std_dev def main(tolerance, runs, silent, no_clean): BENCHMARK_DIR = "./cpp_bench" @@ -96,8 +105,8 @@ def main(tolerance, runs, silent, no_clean): if os.path.exists(f"./{name}.csv"): are_equal, _, _, _, max_diff = compare_csv_files(f"./{name}.csv", f"{OUTPUT_DIR}/{csv_file}", tolerance) formatted_diff = format_difference(max_diff) - cpp_time = '{:.4f}s'.format(cpp_times[name]).rjust(8) - julia_time = '{:.4f}s'.format(julia_times[name]).rjust(8) + cpp_time = '{:.4f}s'.format(cpp_times[name][0]).rjust(8) + julia_time = '{:.4f}s'.format(julia_times[name][0]).rjust(8) result = f"{padded_name}: {'Success' if are_equal else 'Failure'} (Max Diff: {formatted_diff}, C++: {cpp_time}, Julia: {julia_time})" result_color = GREEN if are_equal else RED results_dict[name] = f"{result_color}{result}{NC}"