MATLAB: Parsim: Create SimulinkInput Object from currently open model with initial values

Parallel Computing Toolboxparforparsimsimulinksimulinkinput

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?

Best Answer

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