Workers in parfor writing to files of a Simulink Model

조회 수: 1 (최근 30일)
lingyan
lingyan 2013년 7월 25일
Hi all, i'm using parfor to running a simulink model. But multiple workers attempt to write to the same file, and i found a solution here: http://www.mathworks.de/de/help/simulink/ug/running-parallel-simulations.html#brsk7nj (A Model with Stateflow, MATLAB Function Block, or Model Block).
But after i changed code, every time when the simulink model is called, will this model new compiled and this makes time of running the model much longer. If i don't change the code, the model running much faster, but after a few loops exits error. So what should i do to make the model run faster and without error.
*|My idea is to create a temp file for each worker, so that the model will only once compiled at the first time it be called. But i still don't known, how to create these files.||*|
rk1 = [50 75 16.667 33.333 85 50 85 16.777];
rk2 = [85 85 50 75 16.667 85 95 33.333];
rk3 = [16.667 50 33.333 50 16.667 50 33.333 50 ];
rk4 = [33.333 70 16.777 70 85 70 75 85 ];
if matlabpool('size')==0
matlabpool ('open', 4);
end
parfor j = 1 : length(rk1)
value(j)= CallSim(rk1(j),rk2(j),ts1(j),ts2(j));
end
function [value,fflag] = gp(x)
load('start.mat');
rk1=x(1);
rk2=x(2);
ts1=x(3);
ts2=x(4);
CONTROLSTRATEGY.reku_SOC = [rk1 rk2];
CONTROLSTRATEGY.trq_substitution_SOC = [ts1 ts2];
pr=[];
var = whos;
for i=1:length(var)
assignin('base', var(i).name, eval(var(i).name));
end
if rk1>=rk2 || ts1>=ts2
fflag = 1;
value = 0;
else
fflag = 0;
cwd = pwd;
addpath(cwd);
tmpdir = tempname;
mkdir(tmpdir)
cd(tmpdir)
tic;
sim('XRSimWWPen01');
toc;
OUTPUT_ELSYS_BAT_SOC(length(CYCLE.t_soll));
value=OUTPUT_ENG_consumption(length(CYCLE.t_soll))+OUTPUT_SOC(length(CYCLE.t_soll));
OUTPUT_ENG_consumption(length(CYCLE.t_soll));
OUTPUT_SOC(length(CYCLE.t_soll));
cd(cwd)
rmdir(tmpdir,'s')
rmpath(cwd)
end
return;
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Parallel Computing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by