Skip to content

Commit 56aa57f

Browse files
added benchmarks
1 parent 33790d4 commit 56aa57f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

benchmarks/multithreading.jl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ end
2323

2424
# Parse the thread list used by the driver to spawn child Julia processes.
2525
function parse_thread_list()
26-
raw = get(ENV, "QSIM_THREAD_LIST", "1,2,4,8")
26+
raw = get(ENV, "QSIM_THREAD_LIST", nothing)
2727
values = Int[]
28-
for token in split(raw, ',')
29-
stripped = strip(token)
30-
isempty(stripped) && continue
31-
push!(values, parse(Int, stripped))
28+
if raw === nothing
29+
push!(values, 1)
30+
max_threads = Threads.nthreads()
31+
max_threads != 1 && push!(values, max_threads)
32+
else
33+
for token in split(raw, ',')
34+
stripped = strip(token)
35+
isempty(stripped) && continue
36+
push!(values, parse(Int, stripped))
37+
end
3238
end
3339
isempty(values) && push!(values, Threads.nthreads())
3440
values = unique(values)
@@ -61,15 +67,17 @@ function measure_median_seconds(f::Function; repeats::Int, evals::Int)
6167
samples = Vector{Float64}(undef, repeats)
6268
g = f # capture in stable binding for BenchmarkTools interpolation
6369
for idx in 1:repeats
70+
idx != 1 && print("\r sampling trial $(idx)/$(repeats)...")
6471
samples[idx] = @belapsed ($g(); nothing) evals=evals
6572
end
73+
repeats > 1 && println("\r sampling trials complete ")
6674
return Statistics.median(samples)
6775
end
6876

6977
function worker_main()
7078
state_qubits = parse_int_env("QSIM_STATE_QUBITS", "7"; minvalue=2)
71-
density_qubits = parse_int_env("QSIM_DENSITY_QUBITS", "6"; minvalue=2)
72-
repeats = parse_int_env("QSIM_BENCH_REPEATS", "5"; minvalue=1)
79+
density_qubits = parse_int_env("QSIM_DENSITY_QUBITS", "5"; minvalue=2)
80+
repeats = parse_int_env("QSIM_BENCH_REPEATS", "3"; minvalue=1)
7381
evals = parse_int_env("QSIM_BENCH_EVALS", "1"; minvalue=1)
7482
seed = parse_int_env("QSIM_BENCH_SEED", "1234"; minvalue=0)
7583

@@ -155,12 +163,16 @@ function driver_main()
155163
project_path = Base.active_project()
156164
cmd_base = project_path === nothing ? `$(Base.julia_cmd()) $(abspath(@__FILE__))` : `$(Base.julia_cmd()) --project=$(project_path) $(abspath(@__FILE__))`
157165

158-
for threads in thread_list
166+
total = length(thread_list)
167+
for (idx, threads) in enumerate(thread_list)
168+
println("[$idx/$total] benchmarking with JULIA_NUM_THREADS=$(threads)...")
169+
flush(stdout)
159170
env = copy(ENV)
160171
env["JULIA_NUM_THREADS"] = string(threads)
161172
env["QSIM_BENCH_WORKER"] = "1"
162173
output = read(setenv(cmd_base, env), String)
163174
push!(results, parse_result(output))
175+
println("[$idx/$total] finished threads=$(threads)")
164176
end
165177

166178
isempty(results) && return

0 commit comments

Comments
 (0)