340 likes | 478 Views
CSIM19 tutorial. Reference: http://www.mesquite.com/. Introduction. CSIM19 A library of routines Process-oriented, discrete-event simulation package for use with C or C++ programs A CSIM program It models a system as a collection of CSIM processes which interact with each other.
E N D
CSIM19 tutorial Reference: http://www.mesquite.com/
Introduction • CSIM19 • A library of routines • Process-oriented, discrete-event simulation package for use with C or C++ programs • A CSIM program • It models a system as a collection of CSIM processes which interact with each other
Introduction • CSIM provides the following simulation objects: • CSIM processes: processes • CSIM objects: facilities, storages, buffers, events, mailboxes • Statistics: tables, qtables, meters, …
Simulation time • CSIM maintains a simulation clock, with value equals to current time in the model • Different from the CPU time used or the “real world” time • Starts at zero • A double precision floating point
Simulation time • Retrieving the current time • 1. Simtime function • Prototype: double simtime (void); • Example: x = simtime (); • 2. Reference the variable clock • Example: x = clock; • Delaying for an amount of time • Prototype: void hold (double amount_of_time); • Example: hold (1.0);
Process • It is the active entities in a model • It is a procedure which executes the create statement • A process must be in four states • Active computing • Ready to begin computing • Holding • Waiting for an event
Initiating a process • Prototype: void proc (arg1, … , argn); • Example: my_proc (a, 64, “proc”); • Note: • A create statement must appear in the initiated process • A process cannot return a function value
Creating a process • Prototype: void create (char* name); • Example: create (“customer”); • Note: • Executes at the beginning of a process • Process can initiate other processes • No simulation time passes
Process operation • Processes appear to operate simultaneously at the point in simulation time • Processes execute until they suspend themselves by: • Execute a hold statement • The process is put into a queue • Execute a csim_terminate statement
Terminating a process • A process terminates when • A normal procedure exit, or • Executes a terminate statement • Prototype: void csim_terminate (void); • Example: csim_terminate ();
Changing the process priority • Initial priority of a process is inherited from the initiator of that process • Default priority is 1 • Prototype: void set_priority (long new_priority); • Example: set_priority (5); • Note: • Must appear after the create statement • Lower values represent lower priorities
Reporting process status • Print the status of each active process • Prototype: void status_processes (void); • Example: status_processes ();
Facilities • It models a resource in a simulated system • Processes are ordered in a facility queue by their priorities. • A higher priority process is ahead of a lower priority process.
Declaring and initiating a facility • Declaring: • Dynamic example: facility *fd; • Initiating: • Prototype: facility::facility (char *name); • Dynamic example: fd = new facility (“fac”); • Static example: facility fs (“fac”); • Note: • The facility name is only used only to identify the facility in output reports and trace messages
Using a facility • A process can use a facility for a specified interval of time. • If the facility is free, then the process gains exclusive use of the server until the end of the usage interval • If the facility is busy, then the process is put in a queue of waiting processes. • Prototype: void facility::use (double service_time); • Example: fd->use(1.0);
Reserving and releasing a facility • In case a process acquires a server other than entering the usage interval • Reserve: to gain exclusive use of a server • Release: to relinquish use of the server • Prototype: void facility::reserve (void); void facility::release (void); • Dynamic example: • fd->reserve (); fd->release ();
Reserving and releasing a facility • Note: • When a process executes a reserve, it either • 1) gets use of the server, or • 2) it is suspended and placed in a waiting queue • The process releasing a server must be the same process reserved it. Otherwise, use release_server () • “fd->reserve (f); hold (t); fd->release (f);” = fd->use (t); • “fd->reserve (f); hold (exponential(t)); fd->release (f);” =!= fd->use (exponential(t));
Producing reports • Prototype: void facility_report (void); • Example: facility_report ();
Releasing a specific server at a facility • Used when one process reserves a facility and then for another process to release • Prototype: void facility::release_server (long server_index); • Dynamic example: server_index = fd->reserve (); • fd->release_server (server_index); • Note: • The first process has to save the index of the server and gives it to the second process • This is the same as release except the ownership is not checked
Declaring and initializing a multi-server facility • Prototype: facility_ms::facility_ms (char *name, long number_of_servers); • Dynamic example: cpud = new facility_ms (“cpus”, 2); • Static example: facility_ms cpus (“cpus”, 2); • Note: • A process gains access to any free server when reserve()
Facility sets • Prototype: facility_set::facility_set (char *name, long num_of_facilities); • Dynamic example: facility_set *diskd; diskd = new facility_set (“disk”, 10); • Static example: facility_set disks (“disk”, 10); disks[i].use (exponential(1.0));
Events • Used to synchronize the operations of CSIM processes • An event can only be in occurred or not occurred state
Declaring and initializing an event • Prototype: event::event (char *name); • Dynamic example: event *ed; ed = new event (“done”); • Static example: event es (“done)”;
Waiting for an event • Waiting for an event • Prototype: void event::wait (void); • Dynamic example: e->wait (); • Waiting with a time-out • Prototype: long event::timed_wait (double tout); • Dynamic example: res = ed->timed_wait (100.0); if (res != TIMED_OUT) …
Queuing for an event • Prototype: void event::queue (void); • Dynamic example: ed->queue (); • Note: • This behaves like wait function, except that at each time event is set only one queued process is resumed.
Setting an event • Prototype: void event::set (void); • Dynamic example: ed->set (); • Note: • It causes all waiting processes and one queue process to be resumed • If there is no waiting event, the event will be in occurred state upon return from set function
Clearing an event • Prototype: void event::clear (void); • Dynamic example: ed->clear (); • Note: • Clearing an event that is in not occurred state has no effect
Event sets • Prototype: event_set::event_set (char *name, long number_of_events); • Dynamic example: event_set *ed_set; ed_set = new event_set (“events”, 10); • Static example: event_set es_set (“events”, 10); es_set[3].set ();
Producing Report • Status report • Prototype: void status_events (void); • Dynamic example: status_events ();
Tables • To gather statistics on a sequence of discrete values such as interarrival times, service times, … • It does not actually store the recorded values, it just simply updates the statistics • The statistics maintained include: min, max, range, mean, var, std dev, coef of var • Can add histogram, calculation of confidence intervals
Declaring and initializing a table • Prototype: table::table (char *name); • Dynamic example: table *td; • td = new table (“response time”); • Static example: table ts (“response time”);
Tabulating values • Prototype: void table::record (double value); • Dynamic example: td->record (1.0); • Note: • Tables are designed to maintain statistics on data type of type double only
Producing reports • Prototype: void table::report (void); • Dynamic example: td->report (); • Note: • report_tables () to produce reports for all tables
Histograms and confidence intervals • Histograms: • Prototype: void table::add_histogram (long nbucket, double min, double max); • Static example: ts.add_histogram (10, 0.0, 10.0); • Confidence intervals: • Prototype: void table::confidence (void); • Static example: ts.confidence ();