I would like to run a complex Simulink model in a parfor loop on many cores with different data. However, I didn't have success yet so I created a simple model and tried to run it parallel with the same data.
The model looks like this, adding two signals:
With the code:
function Result = Add (X, Y)
Result = X + Y;
The script to run the model is the following:
if matlabpool('size') == 0
matlabpool('open',4);
end
parfor i = 1:4
data=ones(1,20);
X=timeseries(data);
Y=timeseries(data);
output = sim('model_test','StopTime','5');
Result = output.get('Res');
end
However, the following error occurs:
I don't understand why the variables are not existing. I know that paralell computing is always critical in terms of variable access, but I didn't have success with simulink parallel running yet. Can you please explain the error to me and how to solve it? Thank you very much!
Answer to am304: Thank you, the answer helped me in the way that I now know how to change constants with set_param in the parfor loop and I understand why it doesn't work for timeseries. However for timeseries I am still struggling. I tried several versions, also this one:
if matlabpool('size') == 0
matlabpool('open',4);
end
data=ones(1,20);
X=timeseries(data);
Ybase=timeseries(data);
parfor i = 1:4
Y = evalin('base', 'Ybase');
output = sim('model_test','StopTime','5');
Result{i} = output.get('Res');
end
The variable Ybase exists in the workspace, but the following error occurs:
As you see, the variable Ybase exists in the base workspace. Do you know how to use evalin or assignin to access properly?
Thanks and regards!