-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
# # Multithreading speedup for large models | ||
|
||
# In this tutorial we illustrate how to make use of multi threading in BeforeIT to allow for faster | ||
# executions of single simulation runs. | ||
# In this tutorial we illustrate how to make use of multi threading in `BeforeIT.jl` | ||
# to allow for faster executions of single simulation runs. | ||
|
||
import BeforeIT as Bit | ||
using FileIO, Plots, StatsPlots | ||
|
||
|
||
# We then initialise the model, this time we will use the Italy 2010Q1 scenario, | ||
# First, we initialise the model, this time we use the Italy 2010Q1 scenario, | ||
# and we want to simulate the model for a large number of epochs | ||
|
||
parameters = Bit.ITALY2010Q1.parameters | ||
initial_conditions = Bit.ITALY2010Q1.initial_conditions | ||
T = 50 | ||
model = Bit.init_model(parameters, initial_conditions, T); | ||
|
||
|
||
# The model is in scale 1:2000, so it has around 30,000 households | ||
model.prop.H | ||
|
||
println(model.prop.H) | ||
|
||
# Note that households are the sum of active and inactive households and the owners of firms and of the bank | ||
println(length(model.w_act) + length(model.w_inact) + length(model.firms) + 1) | ||
# Note that the households number is actually the sum of active and | ||
# inactive households, the owners of firms and of the bank | ||
length(model.w_act) + length(model.w_inact) + length(model.firms) + 1 | ||
|
||
# Let's fist check how many threads we have available in this Julia session | ||
Threads.nthreads() | ||
|
||
println(Threads.nthreads()) | ||
# Then we need to first compile the code not to count compilation time, | ||
# we can do that just by executing the function one time | ||
Bit.run_one_sim!(model; multi_threading = false) | ||
|
||
# Let's now compare the performance of single threading and multi threading | ||
|
||
model = Bit.init_model(parameters, initial_conditions, T); | ||
@time data = Bit.run_one_sim!(model; multi_threading = false); | ||
|
||
model = Bit.init_model(parameters, initial_conditions, T); | ||
@time data = Bit.run_one_sim!(model; multi_threading = true); | ||
|
||
# Is the speedup in line to what we would expect? | ||
# Is the speedup in line to what we would expect? Yes! |