Timing and Performance Considerations for Co‑Simulation

Suppose we have two models and we wish to set up a co-simulation environment for them using MxTransit. An important property of each model is its Iteration Rate (or Tick Period) and it has a significant impact on the co-simulation setup.

A Potential Performance Problem

Consider the case where Model_S is a Simulink Model and has a tick period of 0.1 millisecond (ms) and Model_C is a VMC model and has a tick period of 1 ms. (In MxTransit, each model could be implemented in Simulink, Statemate, C, C++, or some other modeling environment.) Suppose also that Signal_X is an output of Model_S is an input to Model_C.

Things to note:

Simulink Model_S relinquishes control to MxVDev every 0.1ms. Note there is a small 'Performance Cost' as Windows switches from one process to another.   This Performance Cost is accumulated at a rate of 10 times per millisecond of simulation time.

Nine times out of ten, control is passed directly back to Model_S since Model_C will not be invoked.

One in ten times in this situation, Model_C is invoked.

Some changes in Signal_X may not be seen by Model_C. This is worth noting, but in itself is not a problem since Model_C is essentially sampling every 1ms.

Suppose now we have the same situation, but the Model_S iterates every 10 nanoseconds and Model_C iterates every 1 ms. In this case, the Performance Cost is accumulated at a rate of 100,000 times per millisecond of simulation time. This will result in very slow simulations.

Avoiding this Performance Problem

It is not necessary to transfer control to MxVDev every iteration of Model_S. Model_C will only see the values that are present on its inputs every millisecond when it is invoked.   Limiting control transfer is easily achieved in Simulink by changing the iteration rate of the top level of the Model_S to match Model_C, and deferring to a lower level subsystem the tasks that iterate at higher rates. In this way the high frequency Performance Cost is avoided.

Related Topics:

Tick Period

Choosing a Tick Period for Transforms