Parallel and Distributed Simulation Process Oriented Simulation Outline
Parallel and Distributed Simulation Process Oriented Simulation
Outline • Event-Oriented Simulation (review) • Process-oriented simulation – – Fundamental concepts: Processes, resources Simulation primitives Example Implementation
Event-Oriented Simulation Example • Now: current simulation time • In. The. Air: number of aircraft landing or waiting to land • On. The. Ground: number of landed aircraft • Runway. Free: Boolean, true if runway available Arrival Event: In. The. Air : = In. The. Air+1; If (Runway. Free) Runway. Free: =FALSE; Schedule Landed event @ Now + R; Landed Event: In. The. Air: =In. The. Air-1; On. The. Ground: =On. The. Ground+1; Schedule Departure event @ Now + G; If (In. The. Air>0) Schedule Landed event @ Now + R; Else Runway. Free : = TRUE; Departure Event: On. The. Ground : = On. The. Ground - 1;
Event-Oriented World View Event handler procedures state variables Integer: In. The. Air; Integer: On. The. Ground; Boolean: Runway. Free; Arrival Event { … } Landed Event { … } Departure Event { … } Simulation application Event-oriented simulation programs may be difficult to understand, modify • Program organized around state transitions • Behavior of an aircraft distributed across multiple event handlers • Flow of control among event handlers not obvious
Process Oriented Simulation • Focus simulation program around behavior of entities – Aircraft: arrives, waits for runway, lands, departs • Process-oriented simulation – Process: thread of execution describing entity behavior over time – Resources: shared resource used by entities (e. g. , runway) • Execution: alternate between simulation computations at a single instant of simulation time, and advanced in simulation time (no computation) Computation at a single Instant of simulation time Simulation time advances (no computation) Wallclock time
Simulation Primitives needed to advance simulation time • Advance. Time(T): advance T units of simulation time – Also called “hold” – ex: Advance. Time(R) to model using runway R units of simulation time • Wait. Until(p): simulation time advances until predicate p becomes true – Predicate based on simulation variables that can be modified by other simulation processes – Ex: Wait. Until(Runway. Free) to wait until runway becomes available for landing
Aircraft Process A new aircraft process is created with each Arrival event /* simulate aircraft arrival, circling, and landing */ Integer: In. The. Air; Integer: On. The. Ground; Boolean: Runway. Free; 1 2 3 4 5 6 7 8 9 In. The. Air : = In. The. Air + 1; Wait. Until (Runway. Free); /* circle */ Runway. Free : = FALSE; /* land */ Advance. Time(R); Runway. Free : = TRUE; /* simulate aircraft on the ground */ In. The. Air : = In. The. Air - 1; On. The. Ground : = On. The. Ground + 1; Advance. Time(G); /* simulate aircraft departure */ On. The. Ground : = On. The. Ground - 1;
Implementation Process-oriented simulations are built over event oriented simulation mechanisms (event list, event processing loop) • Event computation: computation occurring at an instant in simulation time – Execution of code section ending with calling a primitive to advance simulation time • Computation threads – Typically implemented with co-routine (threading) mechanism • Simulation primitives to advance time – Schedule events – Event handlers resume execution of processes
Aircraft Process Identify computation associated with each simulation event 1 2 3 4 5 /* simulate aircraft arrival, circling, and landing */ In. The. Air : = In. The. Air + 1; Wait. Until (Runway. Free); /* circle */ Runway. Free : = FALSE; /* land */ Advance. Time(R); Runway. Free : = TRUE; 6 7 8 /* simulate aircraft on the ground */ In. The. Air : = In. The. Air - 1; On. The. Ground : = On. The. Ground + 1; Advance. Time(G); 9 /* simulate aircraft departure */ On. The. Ground : = On. The. Ground - 1; Aircraft Arrival Aircraft Landing Aircraft On The Ground Aircraft Departs
Implementation: Advance. Time(T) Causes simulation time in the process to advance by T units Execute Advance. Time(T): – Schedule Resume event at time Now+T – Suspend execution of thread – Return execution to event scheduler program Process Resume event: – Return control to thread Simulation process … Runway. Free : = FALSE; Advance. Time(R); Runway. Free : = TRUE; . . . Advance. Time(T) { Schedule Resume event at Now+T; Xfer to Schedule } Scheduler { While (sim not done) Remove event from PEL call event handler } later Resume Event Handler { Xfer to sim process }
Implementation: Wait. Until (p) Suspend until predicate p evaluates to true Execute Wait. Until (p): – Suspend execution of thread, record waiting for p to become true – Return execution to event scheduler program Main scheduler loop – For each suspended process, check if execution can resume – Prioritization rule if more than one can resume Simulation process … In. The. Air: =In. The. Air+1; Wait. Until(Runway. Free); Runway. Free: =FALSE; . . . Wait. Until(p) { Add to suspended list Xfer to Schedule } later Scheduler { While (sim not done) Remove ev from PEL call event handler while (a process’s pred is true) Xfer sim process }
Summary • Process-oriented simulation typically simplified model development and modification • Requires threading (e. g. , co-routine) mechanism • Additional complexity and computation overhead to suspend and resume simulation processes
- Slides: 12