parsim: Create SimulinkInput Object from currently open model with initial values
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Good morning everyone,
I am trying to parallelize a large number of Simulink simulations for a Monte Carlo study on a multicore Machine using parsim.
The Help on parsim details, that one has to create a "SimulinkInput object" for each simulation that will run in parsim.
I have my model set up for calculation, initial values and other external values loaded into the model.
What I do not understand is: How can I generate the SimulinkInput Object from my currently open Simulink model? Especially: Without looping over all Input values that are loaded in "from Workspace" blocks? (they are also initial values for my ode)
Currently I run my simulations in nested for loops over all the parameters that change during the study but I think of running the loop for all possible combinations, create the SimulinkInput object for each set of data and afterwards run everything in parallel using parsim, avoiding the nested loops. Is this even possible?
0 Commenti
Risposta accettata
Reid Spence
il 23 Giu 2021
Hi Sebastian,
If I understand correctly you have a lot of variables and inputs in the base workspace, some of these variables change from run to run while others remain constant. Currently you have nested for loops to iterate over all possible combinations and Im guessing you are calling sim() in the deepest nested for loop?
Based on that understanding, I think the best way to transition your code to use parsim is to keep your nested for loops but instead of calling sim() instead use setVariable() on the SimulationInput object for only the variables that are changing from run to run. For all variables in the base workspace that are the same from run-to-run, you can leave those in the base workspace (no need to attach them directly to the SimuationInput object) and then transfer the base workspace to the workers with the "TransferBaseWorkspaceVariables" option on parsim.
Hope that helps
2 Commenti
Reid Spence
il 24 Giu 2021
Exactly, yes use setVariable for the values you want to vary between runs. The Simulink.SimulationInput object does not affect the model file. The point of the input object is to store run specific information in a contained "box" so that you do not have to dirty the model or the workspace to sweep through the iterations. So by that philosophy, no changes to the mode should be required and you can still run a single simulation with sim() afterwards.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Run Multiple Simulations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!