Guy on Simulink

Simulink & Model-Based Design

为实时多功能系统生成代码

Do you generate code to be executed on a multi-core processor? Wouldn't it be cool if you could decide which part of the model will execute on which core?

Controlling the execution of the code generated from a model on a multi-core target

建模并发执行

这个星期,我的朋友特蕾莎修女和你nc, will be introducing a new feature in R2011b designed especially for this:建模并发执行

Teresa and Tunc

特雷莎:在开始之前,我需要清楚一件事:建模并发执行不是利用您的多核处理器来加快桌面模拟的功能。如果您的目标是加快桌面模拟,我建议查看文档部分Improving Simulation Performance and Accuracy并在性能类别of this blog

TUNC:这是正确的。建模并发执行是关于控制从实时快速型和HIL目标的模型生成的代码的执行,例如XPC目标

特雷莎:同时执行以及同时执行的快速原型可以期望多少加速?

TUNC:这实际上取决于模型中有多少并发性。我们已经看到使用三个核心时,已经看到了因子2加速的模型的示例。如果您的模型可以分配到几个任务中,那么加速可能会很重要。

这是如何运作的?

盖伊:I want an example! How can I do that with the model shown above? What do I need to do?

TUNC:首先,您需要使用模型参考blocks. As explained in the设计注意事项文档部分,模型的最高级别只能包括模型块和虚拟连接块。

使用引用模型对模型进行分区

盖伊:这是我的分区模型。我根据模型中的功能进行分区。我有4个组件,该模型似乎尊重顶级模型的约束,下一步是什么?

TUNC:现在,您需要为所有涉及的模型创建并发执行配置集。这可以使用Simulink.SoftwareTarget.concurrentExecutionfunction, or from the Model Explorer:

Adding Concurrent configuration set

特雷莎:完成此操作后,转到顶部模型的配置参数,请检查框说。This is the top of the model hierarchy然后单击Configure Tasks and Map Blocks To Tasksbutton.

打开并发配置集

TUNC:In the Concurrent Execution configuration parameters dialog box, you can define tasks and map blocks to each of these tasks. Let's begin by creating 2 tasks since your processor has 2 cores:

添加定期任务

盖伊:Based on my knowledge of the algorithms present in this model, I think the image processing component contains at least half of the computations. To divide things evenly, I will use one core for image processing and do the rest on the other core:

将任务映射到块

特雷莎:Notice that in the model, color annotations have been added to show which task the blocks are mapped to. Also, you can see a "z-1“表明引入延迟以确保任务之间通信中的数据完整性。

配置为并发执行的模型

盖伊:Nice, so now I can click the build button and run that in real-time on my multicoreXPC目标机器!

How does this scale up?

特雷莎:对于这样的简单模型来说,这很容易,但是使用更多的块和任务可能很复杂。您建议哪种方法来分区更复杂的模型?

TUNC:这是一个迭代过程,需要根据目标在目标方面的表现来完善分区。它需要分析分析。不过,为了开始,Simulink能够使用自动分析金宝app费率来创建最小的分区时间表。您可以单击Get Default Configuration按钮,它将根据任务的速率设置初始映射。

特雷莎:我喜欢。所以,我会从最初的映射中进行改进吗?

TUNC:Exactly.

Now it's your turn

This was just a simple example to illustrate the basic functionality of this feature. I recommend going through使用多层处理器配置目标的模型学习所有可能性!

您对此功能感到兴奋吗?离开我们在这里评论

|

Comments

要发表评论,请单击here登录您的数学帐户或创建一个新帐户。