matlab - Run Simulink model parallel -


i run complex simulink model in parfor loop on many cores different data. however, didn't have success yet created simple model , tried run parallel same data.

the model looks this, adding 2 signals: enter image description here code:

function result  = add (x, y) result = x + y; 

the script run model following:

if matlabpool('size') == 0     matlabpool('open',4); end  parfor = 1:4     data=ones(1,20);     x=timeseries(data);     y=timeseries(data);     output = sim('model_test','stoptime','5');     result = output.get('res'); end 

however, following error occurs: enter image description here

i don't understand why variables not existing. know paralell computing critical in terms of variable access, didn't have success simulink parallel running yet. can please explain error me , how solve it? thank much!

answer am304: thank you, answer helped me in way know how change constants set_param in parfor loop , understand why doesn't work timeseries. timeseries still struggling. tried several versions, one:

if matlabpool('size') == 0 matlabpool('open',4); end  data=ones(1,20); x=timeseries(data); ybase=timeseries(data);  parfor = 1:4     y = evalin('base', 'ybase');     output = sim('model_test','stoptime','5');     result{i} = output.get('res'); end 

the variable ybase exists in workspace, following error occurs:

enter image description here

as see, variable ybase exists in base workspace. know how use evalin or assignin access properly?

thanks , regards!

i suspect it's because data data exists in workspace of main matlab, not in of instances fired matlabpool on workers. have @ workspace access issues in documentation more details on how resolve this, examples illustrating 2 approaches:

the matlab workers, however, not have access workspace of matlab client session model , associated workspace variables have been loaded. hence, if load model , define associated workspace variables outside of , before parfor loop, neither model loaded, nor workspace variables defined in matlab worker sessions parfor iterations executed. typically case when define model parameters or external inputs in base workspace of client session. these scenarios constitute workspace access issues.

[...]

resolving workspace access issues

when simulink model loaded memory in matlab client session, visible , accessible in matlab session; not accessible in memory of matlab worker sessions. similarly, workspace variables associated model defined in matlab client session (such parameters , external inputs) not automatically available in worker sessions. must therefore ensure model loaded , workspace variables referenced in model defined in matlab worker session using following 2 methods.

  • in parfor loop, use sim command load model , set parameters change each iteration. (alternative: load model , use g(s)et_param command(s) set parameters in parfor loop)
  • in parfor loop, use matlab evalin , assignin commands assign data values variables. alternatively, can simplify management of workspace variables defining them in model workspace. these variables automatically loaded when model loaded worker sessions. there are, however, limitations method. example, cannot have tunable parameters in model workspace. detailed discussion on model workspace, see model workspaces.

edit

here's in particular example:

if matlabpool('size') == 0    matlabpool('open',4); end  data=ones(1,20); x=timeseries(data); y=timeseries(data);  parfor = 1:4     assignin('base','y',y);     output = sim('model_test','stoptime','5');     result{i} = output.get('res'); end 

another option include x , y in model workspace model self-contained.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -