How can I use parsim command for my simulink model to perform parallel simulation for the given code?

5 次查看(过去 30 天)
I am facing while using the parsim command for running my simulations on simulink. IN the code below, I am using a nested for loop. I have called all 3 simulation objects as 'in' with different indexing i1, i2 and i3 for the parameters below.
My code on compiling (without using parallel computing) creates a structure called 's' which stores signals in base workspace. However, when using the parsim command, variable 's' is not found.
Part of code :
modelname = 'SEC_final' ;
% parameters to be used in simulink
dist_5thwheel_to_second_axle_sem2_itr = [7.13, 7.63];
dist_front_trailer_to_5thwheel_sem2_itr = [1.368, 1.668];
dist_pin_coupling_to_dolly_centre_itr = [3.3, 3.8, 4.3]; %drawbar length
%size of above parameters
counter1 = length(dist_5thwheel_to_second_axle_sem2_itr);
counter2 = length(dist_front_trailer_to_5thwheel_sem2_itr);
counter3 = length(dist_pin_coupling_to_dolly_centre_itr);
for i1 = 1:1:counter1 %counter for parameter1
in(i1) = Simulink.SimulationInput(modelname); %simulation object 1 for model
in(i1) = setBlockParameter(in(i1), [modelname '/Semitrailer 2'], 'dist_5thwheel_to_second_axle_sem2', num2str(dist_5thwheel_to_second_axle_sem2_itr(i1)));
for i2 = 1:1:counter2 %counter for parameter2
in(i2) = Simulink.SimulationInput(modelname); %simulation object 2 for model
in(i2) = setBlockParameter(in(i2), [modelname '/Semitrailer 2'], 'dist_front_trailer_to_5thwheel_sem2', num2str(dist_front_trailer_to_5thwheel_sem2_itr(i2)));
for i3 = 1:1:counter3
in(i3) = Simulink.SimulationInput(modelname); %simulation object 3 for model
in(i3) = setBlockParameter(in(i3), [modelname '/Semitrailer 2'], 'dist_front_trailer_to_5thwheel_sem2', num2str(dist_front_trailer_to_5thwheel_sem2_itr(i3)));
% assigning the reference parameters in base workspace
assignin('base','tmax',tmax);
assignin('base','dt',dt);
assignin('base','Vx',Vx);
assignin('base','X0',X0);
assignin('base','rdfname',rdfname);
assignin('base','rdfname_inner',rdfname_inner);
assignin('base','steer_input',steer_input);
assignin('base','brake_input',brake_input);
assignin('base','throttle_input',throttle_input);
assignin('base','Vx_input',Vx_input);
assignin('base','end_posy',end_posy)
assignin('base','steer_sens_c',steer_sens_c);
assignin('base','steer_ratio',steer_ratio);
assignin('base','steer_control',steer_control);
assignin('base','path_input',path_input);
assignin('base','lookahead_time',lookahead_time);
assignin('base','T_lag',T_lag);
modelname = 'SEC_final';
% sim(modelname,[],simset('DstWorkspace','base')); % command for normal simulation (not using parallel computing)
out_1 = parsim(in, 'ShowProgress', 'on'); %parsim command
evalin('base',['save ..\simresults\',modelname,' s VR dt']) %s is a structure containing many signals from simulation
end
end
end
%% ------------- My command window display on running the above code ----------------%%
[14-Aug-2021 23:35:40] Loading model on parallel workers...
[14-Aug-2021 23:36:18] Running simulations...
[14-Aug-2021 23:36:46] Completed 1 of 1 simulation runs. Run 1 has errors.
Warning: Simulation(s) with indices listed below completed with errors. Please inspect the corresponding SimulationOutput to get
more details about the error:
[1]
[14-Aug-2021 23:36:46] Cleaning up parallel workers...
Error using save
Variable 's' not found.
Error in Example_Training_90_deg_exit (line 252)
evalin('base',['save ..\simresults\',modelname,' s VR dt'])
  1 个评论
Reid Spence
Reid Spence 2021-8-18
Parsim does not return outputs of things like ToWorkspace Blocks to the base workspace but instead returns them inside the Simulink.SimulationOutput object which for you is "out_1". You will need to index the output object to find the variable "s".
It looks like out_1 also contains an error message for the simulation. Consider using ">>out_1.ErrorMessage" or use the "SimulationManager" option on parsim to see the error message and address it. My guess is that you will have to use the 'TransferBaseWorkspace' option for parsim since it looks like your model parameters preside in the base workspace.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Run Multiple Simulations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by