Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trial using threading to run events simultaneously #1327

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

willGraham01
Copy link
Collaborator

@willGraham01 willGraham01 commented Apr 30, 2024

Proof of Concept

At present, the simulation runs by working through the event queue in serial, and the simulation is deemed complete when the date of the next event in the queue exceeds the end date of the simulation.

We should be able to use threading to run multiple events simultaneously in different threads; so long as the events that run are not going to interfere with each other (target the same patient, advance time before events the previous day finish, etc).

This PR implements

  • ThreadedSimulation class. Essentially identical to the existing Simulation class, but utilises a pool of threads to execute events in the simulation event queue simultaneously when possible. When an event is deemed unsafe to be run in parallel to others, the "threads" are allowed to finish working on the events they have already been given, then the unsafe event is run in the main thread, and then delegation of work is resumed.
  • ThreadController class. For handling the multiple threads that we'll need when running events simultaneously.
  • Refactors the majority of the Simulation class into the _BaseSimulation class, from which Simulation now inherits. This is to avoid a large amount of code repetition (as now Simulation and ThreadedSimulation can inherit rather than redefine).
  • Adds a CLI to the scale_run profiling script to allow for the option of using a ThreadedSimulation.

TODO

  • This only speeds up the execution of simulation events, but the most recent profiling results indicate that the HealthCareSystem population-level event is really what is slowing the simulation down. This population-level event also has a HSI-event-queue that it works through in serial, so we might be able to apply the same threading logic here to provide further speedup.

@willGraham01 willGraham01 changed the title Threading for Simulations Trial using threading to run events simultaneously May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant