Main Content

Modeling for Single-Tasking Execution

Single-Tasking Mode

您可以严格执行模型代码single-tasking manner. While this mode is less efficient with regard to execution speed, in certain situations, it can simplify your model.

In single-tasking mode, the base sample rate must define a time interval that is long enough to allow the execution of all blocks within that interval.

下图说明了单任务执行中固有的效率低下。

定时图显示了单任务执行的效率低下

单任务系统执行需要一个足够长的基本样本率,以在整个模型中执行一步。

构建一个用于单任务执行的程序

To use single-tasking execution, clear model configuration parameter将每个离散率视为单独的任务. If you select the parameter, single-tasking mode is used in the following cases:

  • If your model contains one sample time

  • If your model contains a continuous and a discrete sample time and the fixed step size is equal to the discrete sample time

Single-Tasking Execution

此示例研究了使用固定步骤求解器,简单的多培训模型如何实时和仿真执行。它考虑通过设置模型配置参数确定的单任务和多任务模式的操作将每个离散率视为单独的任务.

The example model is shown in the next figure. The discussion refers to the six blocks of the model as A through F, as labeled in the block diagram.

The execution order of the blocks (indicated in the upper right of each block) has been forced into the order shown by assigning higher priorities to blocks F, E, and D. The ordering shown is one possible valid execution ordering for this model. For more information, see动态系统中的仿真阶段.

The execution order is determined by data dependencies between blocks. In a real-time system, the execution order determines the order in which blocks execute within a given time interval or task. This discussion treats the model's execution order as a given, because it is concerned with the allocation of block computations to tasks, and the scheduling of task execution.

Note

The discussion and timing diagrams in this section are based on the assumption that the Rate Transition blocks are used in the default (protected) mode, with block parametersEnsure data integrity during data transferEnsure deterministic data transfer (maximum delay)selected

This example considers the execution of the above model when model configuration parameter将每个离散率视为单独的任务is cleared, which indicates the single-tasking mode.

In a single-tasking system, if you select model configuration parameterBlock reduction, fast-to-slow Rate Transition blocks are optimized out of the model. The default case is shown (parameterBlock reductionselected), so block B does not appear in the timing diagrams in this section. For more information, seeBlock reduction.

下表显示了模型中的每个块,执行顺序,示例时间以及块是否具有输出还是更新计算。块A没有离散状态,因此没有更新计算。

Execution Order and Sample Times (Single-Tasking)

Blocks
(in Execution Order)

Sample Time
(片刻之间)

Output

Update

E

0.1

Y

Y

F

0.1

Y

Y

D

1

Y

Y

A

0.1

Y

N

C

1

Y

Y

实时单任务执行

下图显示了将生成代码部署在实时系统中时的计算计划。在10 Hz计时器的中断下,实时显示生成的程序。

定时图显示在实时系统中部署生成代码时计算的调度

At time 0.0, 1.0, and every second thereafter, both the slow and fast blocks execute their output computations; this is followed by update computations for blocks that have states. Within a given time interval, output and update computations are sequenced in block execution order.

快速块以0.1秒的间隔在每个tick上执行。输出计算之后是更新计算。

该系统在每个时间间隔的一部分(标记为“等待”)空转。在只有快速块执行的时间间隔内,闲置的间隔很大。这说明了单任务模式的固有效率低下。

Simulated Single-Tasking Execution

The next figure shows the execution of the model during the Simulink®simulation loop.

Timing diagram that shows execution of the model during the Simulink simulation loop

Because time is simulated, the placement of ticks represents the iterations of the simulation loop. Blocks execute in exactly the same order as in the previous figure, but without the constraint of a real-time clock. Therefore there is no idle time between simulated sample periods.

相关话题