Вы находитесь на странице: 1из 4

4/8/2015

ParallelSimulationsUsingParfor:TestCaseSweepMATLAB&SimulinkExampleMathWorksIndia

ParallelSimulationsUsingParfor:TestCaseSweep
ThisexampleshowshowyoucanrunmultipleSimulinksimulationscorrespondingtodifferenttestcasesinthe
SignalBuilderblock,inparallelbyusingtheParallelComputingToolbox.Thisinvolvesfivemainsteps:
1. StartMATLABworkersonyourmachine
2. Setupdatarequiredforthemultiplesimulations
3. Runmultiplesimulationsina parfor (parallel for )loop
4. Plotresultsofmultiplesimulations
5. CloseMATLABworkers
ModelOverview
Themodelsldemo_suspn_3dofshownbelowsimulatesthevehicledynamicsbasedontheroadsuspension
interactionfordifferentroadprofiles.Thevehicledynamicsarecapturedinthreedegreesoffreedom:vertical
displacement,roll,andpitch.TheroadprofiledatafortheleftandrighttiresisimportedintotheSignalBuilderblockas
differenttestcases.TheRoadSuspensionInteractionsubsystemcalculatesthesuspensionforcesonthevehicleat
thefourtirelocationsbasedontheroaddataandthecurrentvehiclestate.IntheBodyDynamicssubsystemthese
forcesandtheresultingpitchandrollmomentsareusedtodeterminethevehiclemotioninthreedegreesoffreedom:
verticaldisplacement,roll,andpitch.
Thesuspensionmodelissimulatedusingdifferentroadprofilestodetermineifthedesignmeetsdesiredperformance
goals.ParallelComputingToolboxisusedtospeedupthesemultiplesimulations,asillustratedbelow.

mdl='sldemo_suspn_3dof';
isModelOpen=bdIsLoaded(mdl);
open_system(mdl);

http://in.mathworks.com/help/simulink/examples/parallelsimulationsusingparfortestcasesweep.html?prodcode=SL

1/4

4/8/2015

ParallelSimulationsUsingParfor:TestCaseSweepMATLAB&SimulinkExampleMathWorksIndia

Step1:StartMATLABWorkersonYourMachine
FirstconfigureandstartapoolofMATLABworkers.Usethe parpool commandtocheckifaparallelpoolisopen,
andthenopenalocalpoolonyourmulticoredesktop.ThisrequiresParallelComputingToolbox.

apool=gcp('nocreate');
ifisempty(apool)
apool=parpool;
end
Startingparallelpool(parpool)usingthe'local'profile...connectedto12
workers.
Step2:SetupDataRequiredfortheMultipleSimulations
DeterminethenumberofcasesintheSignalBuilderblockusingthesignalbuilderfunction.Thenumberofcasesis
usedtodeterminethenumberofiterationstoruninstep3.Thenumberofcasesisalsousedtopreallocateanarrayof
SimulationOutputobjectsintheSimulinkpackagethatwillbeusedtocollectthesimulationresultsinstep3.

[~,~,~,cases]=signalbuilder([mdl'/RoadProfiles']);
numCases=numel(cases);
simout(numCases)=Simulink.SimulationOutput;
Step3:RunMultipleSimulationsina parfor (Parallel for )Loop
RunmultiplesimulationscorrespondingtothedifferenttestcasesintheSignalBuilderblockwithina parfor loop.
The signalbuilder functionisusedagainherebutthistimetosettheactivesignalineachiteration.Thesim
commandreturnsallthesimulationdataasaSimulationOutputobjectoftheSimulinkpackage.Notethatthe
simulationresultsarecollectedinthesimoutvariable,whichwaspreallocatedinstep2.

parforidx=1:numCases
load_system(mdl);
signalbuilder([mdl'/RoadProfiles'],'activegroup',idx);
http://in.mathworks.com/help/simulink/examples/parallelsimulationsusingparfortestcasesweep.html?prodcode=SL

2/4

4/8/2015

ParallelSimulationsUsingParfor:TestCaseSweepMATLAB&SimulinkExampleMathWorksIndia

simout(idx)=sim(mdl,'SimulationMode','normal');
end
Step4:PlotResultsofMultipleSimulations
Plottheverticalvehicledisplacementfromthedifferentsimulationstoseehowthevehicleperformedtothedifferent
roadprofiles.Usethe get methodoftheSimulationOutputobjecttoobtainthetimeseriescontainedineachelement
ofsimout.Thetimeandandsignaldataarecontainedwithinthetimeseriesobject.

legend_labels=cell(1,numCases);
fori=1:numCases
si=simout(i);
ts=si.get('logsout').get('vertical_disp').Values;
ts.plot;
legend_labels{i}=['Run'num2str(i)];
holdall
end
title('Responseofa3DoFSuspensionModel')
xlabel('Time(s)');
ylabel('Vehicleverticaldisplacement(m)');
legend(legend_labels,'Location','NorthEastOutside');

Step5:CloseMATLABWorkers
Last,closetheparallelpoolandthemodeliftheywerenotpreviouslyopened.
http://in.mathworks.com/help/simulink/examples/parallelsimulationsusingparfortestcasesweep.html?prodcode=SL

3/4

4/8/2015

ParallelSimulationsUsingParfor:TestCaseSweepMATLAB&SimulinkExampleMathWorksIndia

if(~isModelOpen)
close_system(mdl,0);
end
delete(apool);
ContactSales(http://www.mathworks.com/company/aboutus/contact_us/contact_sales.html?
eventid=1448245335&s_iid=mex_sales_SL_tb)
ProductTrial(http://www.mathworks.com/programs/trials/trial_request.html?
prodcode=SL&eventid=565531742&s_iid=mex_trial_SL_tb)
PricingandLicensing(http://www.mathworks.com/pricinglicensing/?prodcode=SL&s_iid=mex_pl_SL_tb)
MATLABStudent(http://www.mathworks.com/academia/student_version/)

ProductResources
Documentation(http://www.mathworks.com/help/simulink/)
HardwareSupport(http://www.mathworks.com/hardwaresupport/?
q=%20product_family:%22Simulink+Product+Family%22)
TechnicalArticles(http://www.mathworks.com/company/newsletters/search.html?q=product:%22Simulink%22)
SystemRequirements(http://www.mathworks.com/products/availability/#SL)

TrySimulink
Gettrialsoftware(http://www.mathworks.com/programs/trials/trial_request.html?
prodcode=SL&eventid=565531742&s_iid=mex_trial_SL_callout)

http://in.mathworks.com/help/simulink/examples/parallelsimulationsusingparfortestcasesweep.html?prodcode=SL

4/4

Вам также может понравиться