1- # TODO Cleanup
1+ # For local testing :
22# using Pkg
33# Pkg.develop("PlantSimEngine")
44# using PlantSimEngine
55using Statistics
6- using DataFrames
7- using CSV
6+ # using DataFrames
7+ # using CSV
88using Random
99using PlantBiophysics
10- using BenchmarkTools
11- using Test
12- using PlantMeteo
10+ # using BenchmarkTools
11+ # using Test
12+ # using PlantMeteo
1313
1414function benchmark_plantbiophysics ()
1515
@@ -60,7 +60,7 @@ function benchmark_plantbiophysics()
6060
6161
6262 constants = Constants ()
63- time_PB = Vector {Float64} (undef, N* microbenchmark_steps)
63+ # time_PB = Vector{Float64}(undef, N*microbenchmark_steps)
6464 for i = 1 : N
6565 leaf = ModelList (
6666 energy_balance= Monteith (),
@@ -92,64 +92,90 @@ function benchmark_plantbiophysics()
9292 # return time_PB
9393end
9494
95- #= @testset "PlantBiophysics benchmark" begin
96-
97- time_PB = benchmark_plantbiophysics()
98- N = length(time_PB)
99- #statsPB = (mean(time_PB), median(time_PB), Statistics.std(time_PB), findmin(time_PB), findmax(time_PB))
100- min__ = findmin(time_PB)[1]
101- max__ = findmin(time_PB)[1]
102- @test min__ > 1e-7
103- @test max__ < 1e-5
104- @test mean(time_PB) > 5e-7
105- @test mean(time_PB) < 5e-6
106- #TODO
107- end=#
108-
109- #=
110- function run_plantbiophysics()
111-
112-
113- Rs = 10.0
114- Ta = 18.0
115- Wind = 0.5
116- P = 90.0
117- Rh = 0.1
118- Ca = 360.0
119- skyF = 0.0
120- d = 0.001
121- Jmax = 200.0
122- Vmax = 150.0
123- Rd = 0.3
124- TPU = 5.0
125- g0 = 0.001
126- g1 = 0.5
127- vpd = e_sat(Ta) - vapor_pressure(Ta, Rh)
128- PPFD = Rs*0.48*4.57
95+ function setup_benchmark_plantbiophysics_multitimestep ()
12996
130- constants = Constants()
97+ Random. seed! (1 ) # Set random seed
98+ N = 100 # Number of timesteps simulated for each microbenchmark step
13199
132- leaf = ModelList(
100+ length_range = 10000
101+ Rs = range (10 , 500 , length= length_range)
102+ Ta = range (18 , 40 , length= length_range)
103+ Wind = range (0.5 , 20 , length= length_range)
104+ P = range (90 , 101 , length= length_range)
105+ Rh = range (0.1 , 0.98 , length= length_range)
106+ Ca = range (360 , 900 , length= length_range)
107+ skyF = range (0.0 , 1.0 , length= length_range)
108+ d = range (0.001 , 0.5 , length= length_range)
109+ Jmax = range (200.0 , 300.0 , length= length_range)
110+ Vmax = range (150.0 , 250.0 , length= length_range)
111+ Rd = range (0.3 , 2.0 , length= length_range)
112+ TPU = range (5.0 , 20.0 , length= length_range)
113+ g0 = range (0.001 , 2.0 , length= length_range)
114+ g1 = range (0.5 , 15.0 , length= length_range)
115+ vars = hcat ([Ta, Wind, P, Rh, Ca, Jmax, Vmax, Rd, Rs, skyF, d, TPU, g0, g1])
116+
117+ set = [rand .(vars) for i = 1 : N]
118+ set = reshape (vcat (set... ), (length (set[1 ]), length (set)))'
119+ name = [
120+ " T" ,
121+ " Wind" ,
122+ " P" ,
123+ " Rh" ,
124+ " Ca" ,
125+ " JMaxRef" ,
126+ " VcMaxRef" ,
127+ " RdRef" ,
128+ " Rs" ,
129+ " sky_fraction" ,
130+ " d" ,
131+ " TPURef" ,
132+ " g0" ,
133+ " g1" ,
134+ ]
135+ set = DataFrame (set, name)
136+ @. set[! , :vpd ] = e_sat (set. T) - vapor_pressure (set. T, set. Rh)
137+ @. set[! , :PPFD ] = set. Rs * 0.48 * 4.57
138+
139+ leaf = Vector {ModelList} (undef, N)
140+ for i = 1 : N
141+
142+ leaf[i] = ModelList (
133143 energy_balance= Monteith (),
134144 photosynthesis= Fvcb (
135- VcMaxRef=Vmax ,
136- JMaxRef=Jmax ,
137- RdRef=Rd ,
138- TPURef=TPU ,
145+ VcMaxRef= set . VcMaxRef[i] ,
146+ JMaxRef= set . JMaxRef[i] ,
147+ RdRef= set . RdRef[i] ,
148+ TPURef= set . TPURef[i] ,
139149 ),
140- stomatal_conductance=Medlyn(g0, g1 ),
150+ stomatal_conductance= Medlyn (set . g0[i], set . g1[i] ),
141151 status= (
142- Rₛ=Rs,
143- sky_fraction=skyF ,
144- PPFD=PPFD,
145- d=d,
152+ Rₛ= set . Rs,
153+ sky_fraction= set . sky_fraction ,
154+ PPFD= set . PPFD,
155+ d= set . d,
146156 ),
147157 )
148- deps = PlantSimEngine.dep(leaf)
149- meteo = Atmosphere(T=Ta, Wind=Wind, P=P, Rh=Rh, Cₐ=Ca)
150- st = PlantMeteo.row_struct(leaf.status[1])
151- run!(leaf, deps, 1, st, meteo, constants, nothing)
158+ end
159+
160+ atm = Vector {Atmosphere} (undef, N)
161+ for i in 1 : N
162+ atm[i]= Atmosphere (T= set. T[i], Wind= set. Wind[i], P= set. P[i], Rh= set. Rh[i], Cₐ= set. Ca[i])
163+ end
164+ meteo = Weather (atm)
165+
166+ return leaf, meteo
152167end
153168
154- run_plantbiophysics()
155- =#
169+ function benchmark_plantbiophysics_multitimestep_MT (leaf, meteo)
170+ N = length (meteo)
171+ for i in 1 : N
172+ run! (leaf[i], meteo, Constants (), nothing ; executor = ThreadedEx ())
173+ end
174+ end
175+
176+ function benchmark_plantbiophysics_multitimestep_ST (leaf, meteo)
177+ N = length (meteo)
178+ for i in 1 : N
179+ run! (leaf[i], meteo, Constants (), nothing ; executor = SequentialEx ())
180+ end
181+ end
0 commit comments