Why does adding a Persistent Variable Read or Persistent Variable Write block to my model significantly increase its TET in Simulink Real-Time?

10 次查看(过去 30 天)
I would like to use persistent variables with my Speedgoat real-time machine by using the "Persistent Variable Read" and "Persistent Variable Write" blocks. My application uses hundreds of these blocks, as I need to store hundreds of variables. When using these blocks, I can see that the task execution time (TET) value is highly increased, even causing overruns in some situations. I expected that these blocks should execute only at initialization and termination. Is this not the case?

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2023-3-9
The "Persistent Variable Read" and "Persistent Variable Write" blocks carry execution overhead that will increase the TET at all steps of application execution. As you have noted, using large numbers of these blocks can cause performance issues because each block needs to access the hard disk on the target machine individually. If you are encountering issues with high TET and overruns, please try the following:
1) Reduce the number of read/write blocks by grouping the persistent data together into arrays or non-virtual buses. The performance impact of one block is mostly overhead and increases slowly with data size, so many blocks writing small amounts of data will show much worse performance than a few blocks writing larger amounts of data.
2) Make the sample times of the read/write blocks larger so that they run less frequently.
Additionally, if you have a predetermined and finite stop time, there is a third possible workaround:
3) Place the read/write blocks in conditional subsystems (e.g., an "Enabled Subsystem") to intentionally execute them only when they are needed. For example, you can enable a subsystem containing the  "Persistent Variable Read" block for only the first time step and enable a subsystem containing the "Persistent Variable Write" block for only the final time step and avoid the execution overhead of both blocks for all other steps. Please note that the blocks can only execute their respective read/write actions when they are enabled.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by