使用Simulink模型进行Matlab并行计算 [英] Matlab Parallel Computing with Simulink Model

查看:823
本文介绍了使用Simulink模型进行Matlab并行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,并行计算将是一个巨大的优势.该项目模拟多个Simulink模型.我使用普通的for-Loop进行了仿真,但是由于要花几天的时间进行仿真,因此我决定尝试使用"parfor"-Loop.

I'm working on a project in which parallel computing would be a huge advantage. The project simulates multiple Simulink models. I did the simulation with a normal for-Loop, but since it takes days to simulate I decided to try the "parfor"-Loop.

但这就是问题开始的地方.首先,我将为您提供我的代码,工作区和导致我出现问题的Simulink-part的图片:

But that's where the problem begins. First I'll give you pictures of my code, the workspace and the Simulink-part which is causing me problems:

apool = gcp('nocreate');

if isempty(apool)

apool = parpool('local'); 

end

wpath = pwd;

parfor k = 1:number_of_models  

    load_system(strcat(wpath,'\Models_Folder\',House(k).model_name));
    set_param(House(k).model_name, 'Stoptime', num2str(foreruntime));
    set_param(House(k).mask_name, 'Data_contr', num2str(controlvector(k)));
    set_param(House(k).mask_name, 'Data_cons', strcat('GlobalData(',num2str(k),').consume.',MaskParam(k).consume_input))
    SimOut(k) = sim(House(k).model_name);
end

delete(apool);

令人困惑的是,如果我删除该列:

The confusing thing is if i delete the column:

 SimOut(k) = sim(House(k).model_name);

代码运行正常-> modelparameters设置在

the code just works fine -> the modelparameters are set in a parfor loop

但是如果我不删除列,则会出现以下错误:

but if I don't delete the column the following error appears:

Error using Forerunsimple (line 9)

Error evaluating parameter 'Data_cons' in 'model_house_14/House'

Caused by:

    Error using parallel_function>make_general_channel/channel_general (line 907)
    Error evaluating parameter 'Data_cons' in 'model_house_14/House'
    Error using parallel_function>make_general_channel/channel_general (line 907)
    Undefined variable "GlobalData" or class "GlobalData".

如您在图片中看到的,变量"GlobalData"在工作空间中定义.因此,我认为它应该起作用.显然不是.您知道可能是什么问题吗?

As you can see in the picture the variable "GlobalData" is defined in the workspace. So in my opinion it should work. Obviously it doesn't. Do you have any idea what could be the problem?

推荐答案

您可能想看看这个问题,恕我直言,它是相关的,并且实际上可能是相同的问题:

you may want to see this question, IMHO, it is related, and could in fact be the same problem:

MATLAB:什么在并行模式下运行时,全局变量会发生什么?

即使定义了工作区全局变量,该变量也似乎为空.

There a workspace global variable appears to be empty, even if it was defined.

user Edric 提供了一个链接,并简要说明了全局变量未传递给工作人员(例如simulink以并行方式运行).

user Edric provides a link, and a short explanation, that global variables are not passed to workers (for instance simulink running as parallel).

链接是此博客条目的链接:获取parfor循环并运行": http://blogs .mathworks.com/loren/2009/10/02/using-parfor-loops-getting-and-running/

The link is to this blog entry: "Getting parfor loops up and running": http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/

这篇关于使用Simulink模型进行Matlab并行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆