Mesquite Software

Home
Products and FAQ
Customers
To Order
Contact Us
Site Map
Documentation
News & Events

Purchase & Download
Or, log in here to
access your account.
 
Documentation
User Guide: C : MISCELLANEOUS

21. MISCELLANEOUS

21.1 Real Time

Although, internally, the model only deals with simulated time, the running of the model takes place in real time.

21.1.1 To retrieve the current real time:


Prototype: char* time_of_day(void)
Example: tod = time_of_day();

Where:

  • cur_time - is the actual time of day (type char*)

Notes:

  • 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

21.1.2 To retrieve the amount of CPU time used by the model:

Prototype: double cputime(void)
Example: t = cputime();

Where:

  • t - is the amount of CPU time, in seconds, that has been consumed by the model thus far (type double)

21.2 Retrieving and Setting Limits

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 syntax conventions for these statements are as follows:

  • i - is the returned maximum allowed value for the number of objects of the given type which may exist simultaneously in the model. If this statement changed the value, i will contain the new value. It must be type long.
  • n - is of type long. It is either:
  • Zero - in which case this is strictly an information retrieval request
  • Non-zero - in which case the maximum will be changed to n

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.

21.3 Creating a CSIM Program

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

21.3.1 To process CSIM input parameters from a user-provided main() routine:

Prototype: void proc_csim_args(int * argc, char *** argv)

Where:
argc and argv are the standard C arguments.


Notes:

  • On return, any CSIM arguments have been processed (currently the only CSIM argument is -T (to turn on tracing) and argc and argv have been modified to point to any remaining arguments.

21.3.2 To cause CSIM to perform its necessary cleanup when using a user-provided main() routine:

Prototype: void conclude_csim(void)

Notes:

  • If a model is to be rerun, then the rerun statement should be executed.

21.4 Rerunning or Resetting a CSIM Model

It may be useful to run a model multiple times with different values, or run multiple models in the same program.

21.4.1 To rerun a CSIM model:

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:
    • The random number generator (issue a reset_prob(1) to reset the random number stream)
    • Permanent tables structures

21.4.2 To clear statistics without rerunning the model:

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. buffers 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.

21.4.3 Conclude_flag

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 deleted - an 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))

Where:

  • func - is the name of the function to be called when CSIM detects an error

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)

21.5.3 To print the error message corresponding to the index passed to the error handler:


Prototype: void print_csim_error(long error_number)

Where:

  • index - is the error index for which the error message should be printed (type long)

Notes:

  • The error messages and their indices are listed in section 22, "Error Messages".

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.

21.6 Output File Selection

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:

  • Output file - for reports and status dumps
  • Error file - for error messages
  • Trace file - for traces

21.6.1 To change the file to which a given type of output is sent:

Prototype: void set_error_file(FILE* f)
Prototype: void set_output_file(FILE* f)
Prototype: void set_trace_file(FILE* f)

Where:

  • fp - is a file pointer of the file to which the indicated type of output will be sent (type FILE*)

Notes:

  • Type FILE is normally declared in the standard header file <stdio.h>.
  • The user is responsible for opening and closing the file.

21.7 Compiling and Running CSIM Programs

A CSIM program has to be compiled referencing the CSIM library to process the required "csim.h" header 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.

21.8 Reminders and Common Errors

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).
 
Home | Products/FAQ | Customers | To Order | Contact Us | Site Map | Documentation
© copyright 2005, Mesquite Software, all rights reserved.