Can this parsim get any faster?

1 次查看(过去 30 天)
Hi,
I have to run a large number of simulations to optimize a control system.
In my case,there are 100 controllers to simulate with different conditions, 200 times for each (20'000 simulations). So here is my code just for one
load('Controllers') % Matrix of controller parameters
numberOfControllers = 100 ;
SampleNumber = 200 ;
UnMatrix = unifrnd(-0.1,0.1,SampleNumber,12); % 12 Different situation for each simulation
%% Simulink
a = Simulink.SimulationInput('VPI1');
a = a.setModelParameter ('Solver' , 'ode4' );
a = a.setModelParameter ('FixedStep', '0.05');
a = a.setModelParameter ('StartTime', '0');
a = a.setModelParameter ('StopTime' , '200');
for j = 1: numberOfControllers
a = a.setVariable('x' , Controllers(j,:)) ;
parfor i = 1:SampleNumber
u1(i) = a ;
u1(i) = u1(i).setVariable('un',UnMatrix(i,:));
end
u2 = u1 ;
u2(:) = u2 (:).setModelName('VPI2');
Out1 = parsim( u1 ,'ShowProgress', 'off','TransferBaseWorkspaceVariables','off') ;
Out2 = parsim( u2 ,'ShowProgress', 'off','TransferBaseWorkspaceVariables','off') ;
% Do some thing with Out1 and Out2
end
All files are attached. "VPI1" and "VPI2' are two simulink models. This procedure is going to repeat for another 200 times ( +4'000'000 simulations totally) and because of that is take a long time to finish. I turned "TransferBaseWorkspaveVariables" off to minimize using of RAM.
I was wondering if you know any other ways to speed up this code? For example using "distributed matrices" or another way to set variables to Simulink mode or other "parsim options".
I'm so thankful of your help.
With regards

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Manual Performance Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by