I use parpool and parsim, but only 1 worker 'works' instead of 4.

조회 수: 11 (최근 30일)
Dimosthenis Michaloudis
Dimosthenis Michaloudis 2023년 12월 9일
댓글: Dimosthenis Michaloudis 2023년 12월 13일
I have this Simulink file that runs for 3.84 s. Each 0.04 s. the data changes. I want to use parsim to make the simulation faster. I wrote the code below, but it seems that it uses only one worker (at least only one simulation appears in the manager). Is there any change I should do, or this is the correct way, because its slower than the simple sim command.
% Create a parallel pool if not already available
if isempty(gcp('nocreate'))
parpool; % Create a parallel pool
end
% Load Model & Simulation Input
model = 'zigzag_example_matlab';
Simulink.BlockDiagram.buildRapidAcceleratorTarget(model);
simIn = Simulink.SimulationInput(model);
%Simulation
tic
simout = parsim(simIn, 'TransferBaseWorkspaceVariables', 'on', 'ShowSimulationManager', 'on');
toc
  댓글 수: 2
Edric Ellis
Edric Ellis 2023년 12월 11일
parsim allows you to run multiple simulations in parallel - you should split your data up into pieces, and then run each piece as a separate simulation.
Dimosthenis Michaloudis
Dimosthenis Michaloudis 2023년 12월 11일
You mean like 4 different models? Each one running 0.96? Wouldn't that need also 4 parsims, which would make the thing slower?
Or is it something else entirely?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 12월 11일
이동: Walter Roberson 2023년 12월 12일
You appear to be building a scalar simIn
You should be constructing an array of simulation input objects
The parsim documentation has the example,
FeedTempSweep = 250:10:300;
for i = length(FeedTempSweep):-1:1
in(i) = Simulink.SimulationInput('CSTR');
in(i) = in(i).setVariable('FeedTemp0',FeedTempSweep(i));
end
out = parsim(in, 'ShowSimulationManager', 'on')
Here, 'CSTR' is the name of the model that is to be run.
Each member of the in array defines one simulation to be run. parsim() runs several of the entries in parallel.
  댓글 수: 5
Edric Ellis
Edric Ellis 2023년 12월 13일
It does indeed sound like something isn't quite right there. Are you comparing the parsim time to something like this?
Sweep = 0.00:0.04:3.84;
for i = length(Sweep):-1:1
SampleTime = Sweep(i);
[t, y] = sim(model);
end
Dimosthenis Michaloudis
Dimosthenis Michaloudis 2023년 12월 13일
I compare the parsim to something far simpler. This:
model = 'zigzag_example_matlab.slx';
tic
simout = sim(model,'SimulationMode','rapid');
toc

댓글을 달려면 로그인하십시오.

카테고리

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