simulink output in a parfor loop
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I'm running a model and need to sweep through a lot of parameters so I am using the parallel computing toolbox. I usually use the following type of code and then run a separate function with a normal loop to post process the output file (logsout in this case).
logsout(numsim) = Simulink.SimulationOutput;
parfor jj = 1:numsim
load_system(model);
[kk,ll,mm] = ind2sub(simSpace,jj);
set_param([model '/BA_dynamic/Pitch_dynamic/Mwave'], 'VariableName', mat2str([Force{mm}.Time' Force{mm}.Pitch']));
set_param([model '/PTO_force/Constant1'], 'Value', num2str(PTO.stiffness(ll)));
set_param([model '/PTO_force/Constant3'], 'Value', num2str(PTO.Damper(kk)));
logsout(jj) = sim(model,'ReturnWorkspaceOutputs', 'on');
end
My issue is that I now need to run the simulation for a very large number of parameters so the output file became massive and I run out of memory when trying to post process it. What I then try to do is to get each worker to do the post processing. I have tried the following code:
parfor jj = 1:numsim
load_system(model);
[kk,ll,mm] = ind2sub(simSpace,jj);
set_param([model '/BA_dynamic/Pitch_dynamic/Mwave'], 'VariableName', mat2str([Force{mm}.Time' Force{mm}.Pitch']));
set_param([model '/PTO_force/Constant1'], 'Value', num2str(PTO.stiffness(ll)));
set_param([model '/PTO_force/Constant3'], 'Value', num2str(PTO.Damper(kk)));
logsout = sim(model,'ReturnWorkspaceOutputs', 'on');
addpath([name.folder,'\Post'])
[data]=model_post_003(logsout);
rmpath([name.folder,'\Post'])
Power(jj) = data.PowervsTime(end,jj);
end
I get the following error message:
Error using model_post_003 (line 4)
Attempt to reference field of non-structure array.
Error in single_run_003 (line 101)
parfor jj = 1:numsim
I suspect this has something to do memory access issue from the workers but I find it hard to diagnose what is happening within the workers.
For information below is my post processing function but I don't think it is the cause of the error as it runs with no issues for a normal loop:
function [data]=model_post_003(logsout)
% simulink parameters
data.time = logsout.get('Fdamp_x').Values.Time;
data.Fpto = logsout.get('Force_PTO').Values.Data;
data.PTO_vel = logsout.get('PTO_vel').Values.Data;
%average power .vs. time
InstPow = data.Fpto.*data.PTO_vel; %PTO.Damper*(data.PTO_vel.*data.PTO_vel); %
data.WorkvsTime = cumtrapz(data.time,InstPow);
data.PowervsTime = data.WorkvsTime(2:end)./data.time(2:end);
Thanks in advance for your help.
Alex
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Simulink Environment Customization en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!