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
.
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:
Here's my code:
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);
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".
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?