test: added large scale test with value patterns
[skip ci]
This commit is contained in:
parent
88ecf82477
commit
a064f9de24
@ -1,8 +1,11 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -35,5 +38,10 @@ int main(int argc, char *argv[])
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -41,5 +44,10 @@ int main(int argc, char *argv[])
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -30,5 +33,10 @@ int main(int argc, char *argv[])
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<seconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -32,5 +35,10 @@ int main(int argc, char *argv[])
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
|
||||
66
julia/tests/cpp_bench/BTCS_2027_1999_200.cpp
Normal file
66
julia/tests/cpp_bench/BTCS_2027_1999_200.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// **** GRID ****
|
||||
int rows = 2027;
|
||||
int cols = 1999;
|
||||
Grid64 grid(rows, cols);
|
||||
|
||||
MatrixXd concentrations(rows, cols);
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
concentrations(i, j) = static_cast<double>(i * j) / 1e6;
|
||||
}
|
||||
}
|
||||
concentrations(10, 10) = 15000;
|
||||
concentrations(2020, 1994) = 7500;
|
||||
concentrations(10, 1994) = 7500;
|
||||
concentrations(2020, 10) = 7500;
|
||||
grid.setConcentrations(concentrations);
|
||||
|
||||
// Complex alpha patterns
|
||||
MatrixXd alphax = MatrixXd(rows, cols);
|
||||
MatrixXd alphay = MatrixXd(rows, cols);
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < cols; ++j)
|
||||
{
|
||||
alphax(i, j) = std::sin(i / 100.0) * std::cos(j / 100.0);
|
||||
alphay(i, j) = std::cos(i / 100.0) * std::sin(j / 100.0);
|
||||
}
|
||||
}
|
||||
grid.setAlpha(alphax, alphay);
|
||||
|
||||
// **** BOUNDARY ****
|
||||
Boundary bc = Boundary(grid);
|
||||
bc.setBoundarySideConstant(BC_SIDE_LEFT, 1.5);
|
||||
bc.setBoundarySideConstant(BC_SIDE_RIGHT, 1.5);
|
||||
bc.setBoundarySideConstant(BC_SIDE_TOP, 0.75);
|
||||
bc.setBoundarySideConstant(BC_SIDE_BOTTOM, 0.75);
|
||||
|
||||
// **** SIMULATION ****
|
||||
Simulation simulation = Simulation(grid, bc);
|
||||
simulation.setTimestep(0.005);
|
||||
simulation.setIterations(200);
|
||||
simulation.setOutputCSV(CSV_OUTPUT_ON);
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
@ -1,8 +1,11 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -34,5 +37,10 @@ int main(int argc, char *argv[])
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
using namespace std::chrono;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -42,5 +45,10 @@ int main(int argc, char *argv[])
|
||||
simulation.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
auto start = high_resolution_clock::now();
|
||||
simulation.run();
|
||||
auto stop = high_resolution_clock::now();
|
||||
|
||||
auto duration = duration_cast<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ function main()
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
run(simulation)
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
@ -35,7 +35,7 @@ function main()
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
run(simulation)
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
@ -24,7 +24,7 @@ function main()
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
run(simulation)
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
@ -26,7 +26,7 @@ function main()
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
run(simulation)
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
38
julia/tests/julia_bench/BTCS_2027_1999_200.jl
Normal file
38
julia/tests/julia_bench/BTCS_2027_1999_200.jl
Normal file
@ -0,0 +1,38 @@
|
||||
include("../../tug/Simulation.jl")
|
||||
|
||||
function main()
|
||||
# **** GRID ****
|
||||
rows::Int = 2027
|
||||
cols::Int = 1999
|
||||
|
||||
alphaX = [sin(i / 100) * cos(j / 100) for i in 1:rows, j in 1:cols]
|
||||
alphaY = [cos(i / 100) * sin(j / 100) for i in 1:rows, j in 1:cols]
|
||||
|
||||
grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY)
|
||||
|
||||
concentrations = [i * j / 1e6 for i in 1:rows, j in 1:cols]
|
||||
concentrations[11, 11] = 15000
|
||||
concentrations[2021, 1995] = 7500
|
||||
concentrations[11, 1995] = 7500
|
||||
concentrations[2021, 11] = 7500
|
||||
setConcentrations!(grid, concentrations)
|
||||
|
||||
# **** BOUNDARY ****
|
||||
bc::Boundary = Boundary(grid)
|
||||
setBoundarySideClosed!(bc, LEFT)
|
||||
setBoundarySideConstant!(bc, RIGHT, 1.5)
|
||||
setBoundarySideClosed!(bc, TOP)
|
||||
setBoundarySideConstant!(bc, BOTTOM, 0.75)
|
||||
|
||||
# **** SIMULATION ****
|
||||
simulation::Simulation = Simulation(grid, bc)
|
||||
simulation = setTimestep(simulation, 0.005)
|
||||
simulation = setIterations(simulation, 200)
|
||||
simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF)
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
@ -28,7 +28,7 @@ function main()
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
run(simulation)
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
@ -36,7 +36,7 @@ function main()
|
||||
simulation = setOutputCSV(simulation, CSV_OUTPUT_ON)
|
||||
|
||||
# **** RUN SIMULATION ****
|
||||
run(simulation)
|
||||
print((@elapsed run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
@ -33,19 +33,22 @@ def format_difference(diff):
|
||||
threshold = 1e-5
|
||||
if diff != 0:
|
||||
if abs(diff) < threshold:
|
||||
return '{:.2e}'.format(diff).rjust(9) # Scientific notation for small values
|
||||
return '{:.2e}'.format(diff).rjust(6) # Scientific notation for small values
|
||||
else:
|
||||
return '{:.5f}'.format(diff).rjust(9) # Fixed-point notation for larger values
|
||||
return '{:.3f}'.format(diff).rjust(6) # Fixed-point notation for larger values
|
||||
else:
|
||||
return '0'.rjust(9)
|
||||
return '0'.rjust(6)
|
||||
|
||||
def run_benchmark(command, runs):
|
||||
def run_benchmark(command, runs, precompile=False):
|
||||
times = []
|
||||
for _ in range(runs):
|
||||
start_time = time.perf_counter()
|
||||
subprocess.run(command)
|
||||
output = subprocess.run(command, capture_output=True, text=True)
|
||||
elapsed = time.perf_counter() - start_time
|
||||
times.append(elapsed)
|
||||
if precompile:
|
||||
times.append(float(output.stdout)*1e-9) # Convert from ns to s
|
||||
else:
|
||||
times.append(elapsed)
|
||||
|
||||
avg_time = sum(times) / len(times)
|
||||
min_time = min(times)
|
||||
@ -54,7 +57,7 @@ def run_benchmark(command, runs):
|
||||
|
||||
return avg_time, min_time, max_time, std_dev
|
||||
|
||||
def main(tolerance, runs, silent, no_clean):
|
||||
def main(tolerance, runs, silent, no_clean, precompile):
|
||||
BENCHMARK_DIR = "./cpp_bench"
|
||||
JULIA_DIR = "./julia_bench"
|
||||
COMPILER = "g++"
|
||||
@ -80,7 +83,7 @@ def main(tolerance, runs, silent, no_clean):
|
||||
if not silent: print(f"Compiling {name}...", end="", flush=True)
|
||||
subprocess.run([COMPILER, *CFLAGS, "-o", f"{BIN_DIR}/{name}", f"{BENCHMARK_DIR}/{benchmark}"])
|
||||
if not silent: print(" Running...", end="", flush=True)
|
||||
cpp_times[name] = run_benchmark([f"./{BIN_DIR}/{name}"], runs)
|
||||
cpp_times[name] = run_benchmark([f"./{BIN_DIR}/{name}"], runs, precompile)
|
||||
if not silent: print(" Done.", flush=True)
|
||||
|
||||
# Move CSV files to output directory
|
||||
@ -100,7 +103,7 @@ def main(tolerance, runs, silent, no_clean):
|
||||
padded_name = name.ljust(max_name_length)
|
||||
if os.path.exists(f"{JULIA_DIR}/{name}.jl"):
|
||||
if not silent: print(f"Running {name}...", end="", flush=True)
|
||||
julia_times[name] = run_benchmark(["julia", f"{JULIA_DIR}/{name}.jl"], runs)
|
||||
julia_times[name] = run_benchmark(["julia", f"{JULIA_DIR}/{name}.jl"], runs, precompile)
|
||||
|
||||
if os.path.exists(f"./{name}.csv"):
|
||||
are_equal, _, _, _, max_diff = compare_csv_files(f"./{name}.csv", f"{OUTPUT_DIR}/{csv_file}", tolerance)
|
||||
@ -145,5 +148,6 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--runs', type=int, default=1, help='Number of benchmark runs')
|
||||
parser.add_argument('--silent', action='store_true', help='Run in silent mode without printing details')
|
||||
parser.add_argument('--no-clean', action='store_true', help='Do not clean up temporary files')
|
||||
parser.add_argument('--precompile', action='store_true', help='Use precompiling for Julia benchmarks and rely on benchmark script for timing')
|
||||
args = parser.parse_args()
|
||||
main(args.tolerance, args.runs, args.silent, args.no_clean)
|
||||
main(args.tolerance, args.runs, args.silent, args.no_clean, args.precompile)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user