Although, internally, the model only
deals with simulated time, the running
of the model takes place in real time.
Prototype:
char* time_of_day
(void)
Example:
tod = time_of_day ();
Where:
-
The format of
the returned string is:
day mm dd hh:mm:ss yyyy, for example,
Sun Jun 05 13:22:43 1994 for Sunday,
June 5, 1994 at 1:22:43 PM
Prototype:
double
cputime (void)
Example:
t = cputime ();
Where:
There is a maximum number of each kind
of CSIM data object in a CSIM program.
These maximums can be interrogated and/or
changed. The maximums serve as limits
on the number of structures of a particular
type which exist simultaneously.
21.2.1 To retrieve or change a CSIM
maximum:
The argument for each of the following
statement is interpreted as follows
Prototype:
long max_buffers(long new_max)
Prototype:
long max_classes(long new_max)
Prototype:
long max_events(long new_max)
Prototype:
long max_facilities(long new_max)
Prototype:
long max_histogramslong new_max)
Prototype:
long max_mailboxes(long new_max)
Prototype:
long max_messages(long new_max)
Prototype:
long max_processes(long new_max)
Prototype:
long max_qtables(long new_max)
Prototype:
long max_servers(long new_max)
Prototype:
long max_sizehist(long new_max)
Prototype:
long max_storages(long new_max)
Prototype:
long max_tables(long new_max)
Notes:
-
The maximums apply
to objects which have been both declared
and initialized (and not deleted).
-
Since a histogram
creates a table, the number of active
histograms + active tables cannot
exceed the limit for tables.
-
Because each mailbox
includes an event, the maximum number
of events must include at least one
event per mailbox. Therefore, if the
maximum number of mailboxes is increased,
it is likely that the maximum number
of events must also be increased.
-
It is an error
to change the maximum number of classes
after a collect_class_...
statement has been executed.
There are two distinct ways of writing
CSIM programs:
-
Write a routine
named sim() (the standard approach).
This will cause CSIM to do the following:
-
Generate the
main() routine "under the covers"
-
Perform necessary
initialization
-
Process the
command line
-
Call sim() with
argc
and argv
repositioned to point to the non-CSIM
arguments
-
Provide the main()
routine yourself. This allows you
to imbed the CSIM model in a surrounding
tool. To do this:
-
Call sim() (or
any routine) which becomes the first
(base) CSIM process when it executes
a create
statement
-
Call proc_csim_args
to process the CSIM command line
arguments (if desired)
-
Call conclude_csim
when the simulation model part of
the program is complete
Prototype:
void proc_csim_args
(int * argc, char *** argv)
Where:
Prototype:
void conclude_csim
(void)
Notes:
It may be useful to run a model multiple
times with different values, or run
multiple models in the same program.
Prototype:
void rerun (void)
Notes:
-
rerun
will cause the following to occur:
-
All non-permanent
tables structures are cleared.
-
All processes
are eliminated
-
All facilities,
events, mailboxes, process classes,
storage units, tables and qtables
established before the first create
statement (the create
for the first ("sim")
process) are reinitialized
-
All remaining
facilities, storage units, events,
etc., are eliminated
-
The clock is
set to zero
-
The following
are NOT reset or cleared:
-
Special provisions
are required for C++ programs with
static objects which are constructed
before the program begins execution.
Prototype:
void reset (void)
Notes:
-
reset
will cause the following to occur:
-
All statistics
for facilities and storage units
are cleared.
-
All non-permanent
table structures are cleared
-
the global variable
_start_tm
is set to the current time and is
used as the starting point for calculations
-
All remaining
facilities, storage units, events,
etc., are eliminated
-
The simulated
time clock is set to zero
-
The variable clock
is not altered.
-
Time intervals
for facilities, storage units and
qtables which began before the reset
are tabulated in their entirety if
they end after the reset.
-
This feature can
be used to eliminate the effects of
start-up transients.
Sometimes, it is necessary to delete
some or all of the resources in a model
prior to ending a run. In this case,
an error can be caused when a resource
is deletedan example would be
deleting an event when there are processes
in one of the queues. In some cases,
the resource should be deleted without
causing this error. If the _conclude_flag
variable is non-zero, such errors will
be ignored.
Prototype:
void set_conclude_flag(void)
21.5
Error Handling
When CSIM detects an error, its default
action is to send a message to the error
file and then perform a dump_status.
If this is not satisfactory, the programmer
can, instead, intercept CSIM errors,
and handle them as desired.
21.5.1 To
request that CSIM call a user-specific
error handler:
Prototype:
void set_err_handler
(void (*handler)(long))
Prototype:
void errHandler(long
n);
Example:
set_err_handler(errHandler);
Notes:
-
The function is
called with one argument: the index
of the error that was detected (see
section 22,
"Error Messages", for
a list of errors and their indices).
21.5.2 To
request that CSIM revert to the default
method of handling errors:
Prototype:
void clear_err_handler
(void)
Prototype:
void print_csim_error
(long error_number)
Where:
Prototype:
char*
csim_eror_msg (long n);
Example:
printf ("%d:
%s/n", n, csim_err_msg (n);
Gets string which is error message corresponding
to the CSIM error. The error number
is made available as the argument to
the CSIM error handler procedure.
CSIM allows the user to select where
various types of output should be sent.
The default file for all of these is
"stdout". The following are
the files that can be specified:
Prototype:
void set_error_file
(FILE * f)
Prototype:
void set_output_file
(FILE * f)
Prototype:
void set_trace_file
(FILE * f)
Where:
A CSIM program has to be compiled referencing
the CSIM library to process the required
(the "cpp.h" header file)
and using the CSIM library (archive
file) to satisfy calls to the CSIM library
routines.
For information on installing and using
CSIM18 on specific platforms, please
see the appropriate installation guide.
When writing a CSIM program, the following
things are important:
-
Be aware of the
maximum allowed number of concurrently
active processes. In the current version,
there is a limit of 1000 concurrently
active processes (this can be changed
by using the function max_processes).
-
When a process
(a procedure containing a create
statement) is called with parameters,
these should be either parameters
passed as values (the default in C)
or addresses of variables in global
(or static) storage. Beware of local
arrays and strings which are parameters
for processes...they are likely to
cause problems. THIS IS VERY IMPORTANT!!
CSIM manages processes by copying the
runtime stack to a save area when the
process is suspended and then back to
the stack when the process resumes.
Thus, if a process receives a parameter
which is a local address in the initiating
process (i.e. in that process's stack
frame), the address will not point to
the desired value when the called process
is executing.
-
All entities (facilities,
storage units, etc.) must be declared
using variables of the correct type.
-
All entities (facilities,
storage units, etc.) must be initialized
before being referenced.
-
An array of length
n is indexed 0,1,...,n-1 (standard
C indexing).
|
|