Info

This question is closed. Reopen it to edit or answer.

Having different plots while using parfor loops for MATLAB Simulink

1 view (last 30 days)
I am trying to a parameter sweep of a model using parfor, but I can see from the plots of the results that they are different from the actual simulation results. However, when I replace parfor with for, the results match up. I am clueless as to why this is happening. Any help would be appreciated.
My code:
% 1) Load model and initialize the pool.
model = 'real_mismatch_model';
load_system(model);
matlabpool('open');
% 2) Set up the iterations that we want to compute.
RMS_sweep = [6 18 30];
iterations = length(RMS_sweep);
simout(iterations) = Simulink.SimulationOutput;
% 3) Need to switch all workers to a separate tempdir in case
% any code is generated for instance for StateFlow, or any other
% file artifacts are created by the model.
spmd
% Setup tempdir and cd into it
addpath(pwd);
currDir = pwd;
addpath(currDir);
tmpDir = tempname;
mkdir(tmpDir);
cd(tmpDir);
% Load the model on the worker
load_system(model);
end
% 4) Loop over the number of iterations and perform the
% computation for different parameter values.
parfor idx=1:iterations
set_param('real_mismatch_model/PCC values/RMS2','Freq',num2str(RMS_sweep(idx)));
simout(idx) = sim(model, 'SimulationMode', 'normal');
end
% 5) Switch all of the workers back to their original folder.
spmd
cd(currDir);
rmdir(tmpDir,'s');
rmpath(currDir);
end
close_system(model);
matlabpool('close');

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!