MATLAB Answers

Parallel Simulation

1 view (last 30 days)
Nebitno on 9 Feb 2011
Dear All,
I have a simevents model that can only be run in normal mode. I need to run 100 simulations using different initial seeds. To speed up the process, I would like to run it in parallel on my multi-core computer and store the output of those 100 simulations. The initial seed is denoted N and it takes the value from workspace. I used the following code:
matlabpool open
mdl = 'simModel';
output1 = zeros(1,100); % preallocate memory
parfor ii=1:100
n = round(normrnd(1000,100)); % generate the initial seed
sim(mdl); % simulate the model reading the initial seed n from
% the workspace
output1(1,i) = max(broj); % save the output called "max(broj)"
??? Error using ==> parallel_function at 598 Error in ==> parallel_function>make_general_channel/channel_general at 894 Error occurred in 'simModel/Time-Based Entity Generator'. Error in 'simModel/Time-Based Entity Generator': Initialization commands cannot be evaluated.
Error in ==> uspelo2 at 7 parfor ii=1:100
I would greatly appreciate your help on this.
Sincerely, Nikola

Accepted Answer

Edric Ellis
Edric Ellis on 10 Feb 2011
I assume that your "entity generator" block references the value of "n". To get this to work, you need to give the model access to that variable. Unfortunately, in a PARFOR loop, things are a little more complicated than usual because the body of the PARFOR loop isn't visible to the Simulink model. See: this page for more details. But in short, it should work to do this:
parfor ii = 1:100
assignin( 'base', 'n', round(normrnd(1000,100)) );
sim( mdl );
  1 Comment
Nebitno on 10 Feb 2011
Thanks a lot Edric, it worked. I really appreciate your help. Cheers, Nikola

Sign in to comment.

More Answers (1)

Kaustubha Govind
Kaustubha Govind on 9 Feb 2011
It looks like some SimEvents functions needed for block initialization are not sent to the worker. You could try following the procedure in Technical Solution# 1-AL5N3X to add $matlabroot/toolbox/des/ to the path on all workers.
Nebitno on 10 Feb 2011
Thanks for your time Kaustubha. As Edric said, I was using the local scheduler. Nevertheless, I checked out the link you suggested and it will be useful when I decide to run my simulations on a cluster. Thanks, Nikola

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!