How to use parsim with a Simulink model containing an FMU with dependencies? Model works with sim.

7 views (last 30 days)
Hi,
We have a Simulink model that solves well using the sim command and the Simulink UI "Run" button. The FMU launches a solver process and two talk to each other over ZeroMQ and this works well for one instance. The port that the solver binds to is determined at run time based on the available ports and theoretically this approach should work when multiple simulations are launched in parallel, since no common resources are used or shared. The FMU also needs a few DLLs that are loaded at run time. These are currently placed in the same folder as the Simulink model and runner script.
We have installed the Parallel Computing Toolbox and can run the base example provided. However, when we try to programmatically run our simulations using parsim, it gets stuck on the "loading the model" stage for a long time. We developed our parsim implementation by extending the base example in docs and use setVariable() to assign value to individual simulations. We are also just wanting to parallelize in the "local" context on a 8 core CPU Windows x64 machine. We were wondering, to make sure that the dependencies are correctly getting copied to the individual workers:
  1. Is it possible to view/inspect these temporary directories used by the worker processes? Where are they typically located? I did not find them in the slprj folder.
  2. How can we control which dependencies are copied where? While we do not, for our case, need specific dependencies on specific workers, this maybe needed at times.
  3. Is there a general rule of thumb around how big the FMU should be or the number or size of dependencies or workspace data should be for parsim workers to "work well"?
Also, could we get clarification on the following line in this answer post:
"The 'parsim' function was employed to simulate multiple models specified in the 'SimulationInput' object concurrently. While 'parsim' can effectively reduce the simulation time, it is crucial to structure the model appropriately. Specifically, the simulation should not rely on the results of previous steps. In other words, there should be no dependency between the simulations of the model at different time steps."
Does this mean that in parsim, the model does not keep track of the model state between timesteps? So does this mean we can only solve for one timestep at a time and then relaunch the sim?

Accepted Answer

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU on 26 Aug 2024
Hi Chintan,
Using "parsim" with a Simulink model containing an FMU and dependencies, you can check the following:
Temporary Directories:
  • Worker processes use system-specific temporary directories, accessible via the "tempdir" function. Check these paths by adding diagnostic code to your script.
Dependency Management:
  • Use the "AttachedFiles" property in your "parpool" configuration to ensure all necessary DLLs and dependencies are available to each worker.
Performance Considerations:
  • There's no strict size limit for FMUs or dependencies, but larger sizes may increase setup time. Ensure dependencies are optimized.
Understanding "parsim":
  • "parsim" is designed for independent simulations. Each run should be self-contained without relying on other simulations or previous steps. It is suited for parameter sweeps or Monte Carlo simulations.

More Answers (0)

Categories

Find more on Run Multiple Simulations in Help Center and File Exchange

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!