Issue with setPreSimFcn not being called in MATLAB Parallel Computing Toolbox

3 views (last 30 days)
I have made a test Simulink project to figure out how to attach folders, files and classes to a parallel cluster job and run my model. There are folders that should be attached to the job and some that shouldn't be attached.
The saveFolder is a network drive that the cluster can use.
I open the project, then run the parSim() function:
function simJob = parSim()
%% Setup
%% Fill this part.
% A network drive that the cluster can access
saveFolder = '';
c = parcluster('');
%%
model = 'MyModel';
for i = 1:3
in(i) = Simulink.SimulationInput(model);
logFileName = fullfile(saveFolder, sprintf('logsout%d.mat', i));
in(i).setPreSimFcn(@(x) initWs(i, saveFolder));
%make the simulation run but i want to set the parameter in the
% initWs function
%in(i) = setVariable(in(i), 'param1', Params.MyParam(i)); This will
in(i) = in(i).setModelParameter(...
'StartTime', '0', 'StopTime', num2str(i*10),...
'LoggingFileName', logFileName,...
'LoggingToFile', 'on','SignalLogging', 'on');
end
%% Collect files to attach
filesToAttach = collectFiles();
%% Call batchsim
simJob = batchsim(c, in, ...
'Pool', 3,...
'AutoAddClientPath', false,...
'AutoAttachFiles', false,...
'ManageDependencies', 'off',...
'CurrentFolder', '.',...
'AttachedFiles', filesToAttach);
end
I would like to set up param1 as a class in the setPreSimFcn and log some info later about the folder hierarchy. But it seems it doesn't get called.
I attach the project to test my issue.

Answers (1)

Githin George
Githin George on 19 Dec 2023
Hello Szabó Bence Károly,
It is my understanding that you are trying to use the MATLAB Parallel Computing Toolbox to run a multiple simulation job and are facing an issue with the “setPreSimFcn”. The problem seems to be that the function handle provided as input is not being called.
The issue arises because the “Simulink.SimulationInput” object returned by “setPreSimFcn” is not being assigned to any variable. To correct this issue, you can replace your code with the following line to set the pre-simulation function.
in(i) = in(i).setPreSimFcn(@(x) initWs(i, saveFolder));
I hope this helps.

Categories

Find more on Parallel Computing Toolbox in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!