Skip to content

Commit 17afdc7

Browse files
committed
Update test-performance.jl
fix test on number of threads that was fixed, but can vary depending on the system on which PSE is tested
1 parent 3f12eba commit 17afdc7

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

test/test-performance.jl

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
1+
22
using BenchmarkTools
33
using Dates
44

55
PlantSimEngine.@process "sleep" verbose = false
66

7-
struct ToySleepModel <: AbstractSleepModel
7+
struct ToySleepModel <: AbstractSleepModel
88
end
99

10-
PlantSimEngine.inputs_(::ToySleepModel) = (a = -Inf,)
10+
PlantSimEngine.inputs_(::ToySleepModel) = (a=-Inf,)
1111
PlantSimEngine.outputs_(::ToySleepModel) = NamedTuple()
1212

1313
function PlantSimEngine.run!(m::ToySleepModel, models, status, meteo, constants=nothing, extra=nothing)
@@ -18,27 +18,28 @@ end
1818
PlantSimEngine.TimeStepDependencyTrait(::Type{<:ToySleepModel}) = PlantSimEngine.IsTimeStepIndependent()
1919

2020
meteo_day = read_weather(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), duration=Day)
21-
nrows = nrow(meteo_day)
22-
23-
vc = [0 for i in 1:nrows]
21+
nrows = nrow(meteo_day)
22+
23+
vc = [0 for i in 1:nrows]
2424

2525
models1 = ModelList(process1=ToySleepModel(), status=(a=vc,))
2626
models2 = ModelList(process1=ToySleepModel(), status=(a=vc,))
2727

28-
@testset begin "Check number of threads"
28+
@testset begin
29+
"Check number of threads"
2930
nthr = Threads.nthreads()
3031
@test nthr > 1
31-
32-
t_seq = @benchmark run!(models1, meteo_day; executor = SequentialEx())
32+
33+
t_seq = @benchmark run!(models1, meteo_day; executor=SequentialEx())
3334
#t_seq = run!(models1, meteo_day; executor = SequentialEx())
34-
med_time_seq = median(t_seq).time
35+
med_time_seq = median(t_seq).time
3536

3637
#time is in nanoseconds
3738
@test med_time_seq > nrows * 1000000
3839

39-
t_mt = @benchmark run!(models2, meteo_day; executor = ThreadedEx())
40+
t_mt = @benchmark run!(models2, meteo_day; executor=ThreadedEx())
4041
#t_mt = run!(models2, meteo_day; executor = ThreadedEx())
41-
med_time_mt = median(t_mt).time
42+
med_time_mt = median(t_mt).time
4243

4344
@test med_time_mt > nrows * 1000000 / nthr
4445

@@ -52,13 +53,13 @@ models2 = ModelList(process1=ToySleepModel(), status=(a=vc,))
5253
#end
5354

5455
# unsure how to recover outputs in benchmarked expressions to compare them, rerun the functions as a workaround for now
55-
@test run!(models1, meteo_day; executor = SequentialEx()) == run!(models2, meteo_day; executor = ThreadedEx())
56+
@test run!(models1, meteo_day; executor=SequentialEx()) == run!(models2, meteo_day; executor=ThreadedEx())
5657
end
5758

5859
# TODO make sure a mt test with nthreads == 1 also is tested and is correct
5960
@testset "Single and multi-threaded output consistency" begin
6061
nthr = Threads.nthreads()
61-
@test nthr == 4
62+
@test nthr > 1
6263

6364
using Dates
6465
meteo_day = read_weather(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), duration=Day)
@@ -70,29 +71,30 @@ end
7071
)
7172

7273
tracked_outputs = (:LAI,)
73-
74+
7475
out_seq, out_mt = run_single_and_multi_thread_modellist(models, tracked_outputs, meteo_day)
7576
@test compare_outputs_modellists(out_seq, out_mt)
7677

7778
modellists, status_tuples, outs_vectors = get_modellist_bank()
7879
meteos_all = get_simple_meteo_bank()
79-
80+
8081
# First meteo only has one timestep
8182
meteos = meteos_all[2:length(meteos_all)]
8283

8384
for i in 1:length(modellists)
84-
#i = 1
85+
#i = 1
8586
modellist = modellists[i]
8687
status_tuple = status_tuples[i]
8788
outs_vector = outs_vectors[i]
8889
all_vars = init_variables(modellist)
8990
for j in 1:length(meteos)
9091
meteo = meteos[j]
9192
for k in 1:length(outs_vector)
92-
#k = 1
93-
out_tuple = outs_vector[k]
94-
95-
try out_st, out_mt = run_single_and_multi_thread_modellist(modellist, out_tuple, meteo)
93+
#k = 1
94+
out_tuple = outs_vector[k]
95+
96+
try
97+
out_st, out_mt = run_single_and_multi_thread_modellist(modellist, out_tuple, meteo)
9698
@test compare_outputs_modellists(out_st, out_mt)
9799
catch e
98100
#print(i," ", j, " ", k)

0 commit comments

Comments
 (0)