Introduction To Simulation: Dr. John Mellor-Crummey
Introduction To Simulation: Dr. John Mellor-Crummey
Introduction To Simulation: Dr. John Mellor-Crummey
Next class
how to verify and validate a simulation how long should you run a simulation? how can the same accuracy be achieved with shorter run?
Next week
random number generation how to select RNG seeds how to verify that a RNG is good how to generate random variables with a given distribution
Why simulation?
system under study may not be available
common in design and procurement stages
Why not?
accurate simulation models take a long time to develop
typically the evaluation strategy that takes the longest
Level of detail limited only by time available for development A detailed model may not be a better model
may require more detailed knowledge of input parameters
inaccurate assumptions can yield wrong results example: time to service disk requests for timesharing simulation could use exponential distribution for time for request service could simulate disk rotation and head movement but simulation better only if sector & track locations known
General-purpose languages
more portable provide more control over efficiency and run-time lack support for model development
9
10
All simulation results are suspect Must confirm with at least one of
analytical model measurements intuition
11
12
13
Rule of thumb
use well-known generator rather than rolling your own
Even well-known generators have had problems Improper selection of RNG seeds
seeds for different random streams must be carefully chosen
must ensure independence of streams sources of error share one stream for several different processes use same seed for all streams
impact: introduce correlation among processes that may lead to nonrepresentative results 14
good: more features, parameters to provide better detail bad: add more detail in hope of making it useful
No achievable goal
should have SMART goals
specific, measurable, achievable, repeatable, thorough
not measurable: to model X projects without goals continue until funding runs out
Causes
bugs in simulation program invalid modeling assumptions lack of understanding of system to be modeled
What to do?
attempt to verify the model bring persistent mysterious results to attention of users
may lead to unexpected insight into system may point to system features that must be modeled in more detail
17
18
Is the model reviewed regularly with the end user? Is the model documented?
19
20
Simulation Terminology
State variables: variables that define the state of system Event: change in system state Continuous-time vs. discrete-time models
continuous-time model: system state is defined at all times discrete-time model: state defined only at particular instants
22
Simulation Types
Monte Carlo Trace-driven simulation Program or Execution-driven simulation
24
Monte-Carlo Simulations
Model probabilistic phenomenon that do not change over time Applications
simulation of random or stochastic processes
complex physical phenomena such as radiation transport sub-nuclear processes in high energy physics experiments traffic flow
evaluation of integrals
Requirements
system can be described by probability density functions good pseudo-random number generator available
Trace-driven Simulation
Trace = time ordered record of events on real system Applications: analyze paging, scheduling, caches, etc. Advantages
credibility: easy to sell easy validation: compare with measured system accurate workload: trace preserves correlation & interference effects detailed tradeoffs: possible to evaluate small changes in model less randomness: deterministic input reduces output randomness fair comparison of alternatives similarity of implementation: model is similar to system
Disadvantages
complexity: requires detailed simulation of system representativeness: traces from one system may not be representative finiteness: may not represent much time because of size constraints single point of validation: algorithm good for one trace, not others high level of detail: simulations can be costly hard to evaluate changes in workload characteristics: need another trace
no feedback from simulation of changes that effect event ordering
26
27
Discrete-Event Simulations
Discrete-event simulations use discrete-state model of system
e.g. model number of threads queued for various resources may use discrete or continuous time values
Components
event scheduler: linked list of pending events
operations: schedule event X at time T; hold event X for time interval dt; cancel previously scheduled event X; hold X indefinitely; schedule indefinitely held event unit time or event-driven advancement
system state variables event routines: one for each event type input routines: read model parameters initialization routines for system variables & RNG trace routines: print intermediate results periodically dynamic memory management, usually GC managed storage report generator to calculate and print final result main program: invokes all components in proper order 28
Operations
insert event find next scheduled event remove next scheduled event
Possible implementations
ordered doubly-linked list (used in SIMULA, GASP, GPSS) indexed linear list
divide future into indexed intervals of t each interval has own sublist
29
Thought Questions
30