Possible to prematurely stop single workers in a parsim simulation
Show older comments
I am running a parsim simulation for a simulink model in R2023B. Here, I experience single workers getting stuck in the simulation, during compilation or in a 'queued' state, some of these later aborting the simulation.
For exploratory simulation, it is not necessary for my simulation run to have every simulation successfully run, I can tolerate a few fails for overall speed gain.
So, my idea would be to set a timeout for each simulation and prematurely stop the simulation, ideally with a timeout error for later processing, if the overall worker occupation of a single run exceeds a set time. This should include queueing and compilation.
I have found this related article on stopping the whole pool using a postSimFunction, and plan to use this to evaluate the run time of each other worker after one simulation has finished, stopping these that take too long.
However, I fail to measure single worker duration and aborting a single simulation on a worker from this postSimfunction. Are there any good ways on how to do that?
If that cannot be done, is it possible to place some form or real-time clock in a simulink simulation to detect simulation duration and finish the simulation based on that criterion?
Thank you for your help.
Accepted Answer
More Answers (1)
Jaimin
on 27 Jan 2025
Hi @BW
You can add a clock block to your Simulink model to measure the simulation time. Combine this with a custom block or MATLAB Function block that checks the elapsed time and terminates the simulation if it exceeds a certain threshold.
Kindly refer following code snippet for understanding.
function stopSimBasedOnTime(block)
% Custom MATLAB Function Block
maxSimTime = 300; % Maximum allowed simulation time in seconds
elapsedTime = block.CurrentTime;
if elapsedTime > maxSimTime
set_param(bdroot, 'SimulationCommand', 'stop');
end
end
Use model callbacks like “StartFcn” or “StopFcn” to initialize and check the simulation time, respectively.
For more information kindly refer following MathWorks documentation.
I hope this will be helpful.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!