From 7ad58db3b099b6fc8f8b3d3c05f7590418767c58 Mon Sep 17 00:00:00 2001 From: Cian Hughes Date: Thu, 8 Feb 2024 16:56:08 +0000 Subject: [PATCH] Working test bench for bhmie implementation --- .vscode/launch.json | 17 +++++++++++++ Project.toml | 3 +++ bhmielibs_test.jl | 58 ++++++++++++++++++++++++++++++--------------- 3 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c043748 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "julia", + "request": "launch", + "name": "Run active Julia file", + "program": "${file}", + "stopOnEntry": false, + "cwd": "${workspaceFolder}", + "juliaEnv": "${command:activeJuliaEnvironment}" + } + ] +} \ No newline at end of file diff --git a/Project.toml b/Project.toml index 10dc913..e5788f5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,9 @@ [deps] +AirspeedVelocity = "1c8270ee-6884-45cc-9545-60fa71ec23e4" +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826" diff --git a/bhmielibs_test.jl b/bhmielibs_test.jl index 40e355a..e69a2ae 100644 --- a/bhmielibs_test.jl +++ b/bhmielibs_test.jl @@ -1,5 +1,8 @@ run(`scripts/build_other_impls.sh`) +# using Debugger +using BenchmarkTools + include("src/miemfp.jl") # using miemfp @@ -15,7 +18,7 @@ function bhmie_c(x::Float32, cxref::ComplexF32, nang::UInt32, cxs1::Vector{Compl # Call the C function ccall((:bhmie, ".bhmielibs/bhmie-c/bhmie.so"), Cvoid, - (Float32, ComplexF32, UInt32, Ptr{ComplexF32}, Ptr{ComplexF32}, Ref{Float32}, Ref{Float32}, Ref{Float32}, Ref{Float32}), + (Float32, ComplexF32, UInt32, Vector{ComplexF32}, Vector{ComplexF32}, Ref{Float32}, Ref{Float32}, Ref{Float32}, Ref{Float32}), x, cxref, nang, cxs1, cxs2, qext, qsca, qback, gsca) # Return the output variables @@ -54,27 +57,44 @@ function bhmie_fortran77(x::Float32, refrel::ComplexF32, nang::Int32, s1::Vector return qext[], qsca[], qback[], gsca[] end -# Create test data -x = Float32(1.0) # Example value for x -cxref = ComplexF32(1.5, 0.5) # Example complex refractive index +# Fixed testing values nang = UInt32(2) # Example number of angles -# Example arrays for scattering amplitudes, initialized with dummy complex values -cxs1 = [ComplexF32(0.1, 0.2) for _ in 1:nang] -cxs2 = [ComplexF32(0.3, 0.4) for _ in 1:nang] +c_result = @benchmark bhmie_c(x, cxref, nang, cxs1, cxs2) setup=( + x = rand(Float32); + cxref = rand(ComplexF32); + nang = UInt32($nang); + cxs1 = rand(ComplexF32, $nang); + cxs2 = rand(ComplexF32, $nang); +) -# Test C wrapper -qext, qsca, qback, gsca = bhmie_c(x, cxref, nang, cxs1, cxs2) -println("bhmie_c output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca") +f_result = @benchmark bhmie_fortran(x, cxref, nang, cxs1, cxs2) setup=( + x = rand(Float32); + cxref = rand(ComplexF32); + nang = Int32($nang); + cxs1 = rand(ComplexF32, $nang); + cxs2 = rand(ComplexF32, $nang); +) -# Test Fortran wrapper -qext, qsca, qback, gsca = bhmie_fortran(x, cxref, Int32(nang), cxs1, cxs2) -println("bhmie_fortran output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca") +f77_result = @benchmark bhmie_fortran77(x, cxref, nang, cxs1, cxs2) setup=( + x = rand(Float32); + cxref = rand(ComplexF32); + nang = Int32($nang); + cxs1 = rand(ComplexF32, $nang); + cxs2 = rand(ComplexF32, $nang); +) -# Test Fortran77 wrapper -qext, qsca, qback, gsca = bhmie_fortran77(x, cxref, Int32(nang), cxs1, cxs2) -println("bhmie_fortran77 output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca") +j_result = @benchmark miemfp.bhmie(Float64(x), ComplexF64(cxref), nang) setup=( + x = rand(Float32); + cxref = rand(ComplexF32); + nang = UInt32($nang); +) -# Test Julia wrapper -qext, qsca, qback, gsca = miemfp.bhmie(Float64(x), ComplexF64(cxref), nang) -println("bhmie_julia output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca") \ No newline at end of file +println("\nC Implementation") +display(c_result) +println("\nFortran Implementation") +display(f_result) +println("\nFortran 77 Implementation") +display(f77_result) +println("\nJulia Implementation") +display(j_result)