Build Simulink Real-Time Applications in Parallel

I have a large number of simulink real-time applications that I am trying to build to run on a Speedgoat system. I would like to decrease the build time by running the builds in parallel. It takes 30 minutes to build one application and there are 600+ applications so you can see that building them serially is not a good solution. The models are not dependent on eachother and they are not referenced so the standard built in functionality for parallel model reference bulids with slbuild will not work. The models use data from the base workspace (parameters, configuration reference, bus objects, etc.). I have tried to create a parfor loop detailed below where I save the workspace to a mat file and then load it on each worker before I run slbuild, but I receive the following error.
Error using parallelBuild (line 8)
Unable to find configuration: 'Model_CnfgRef' referenced by 'TC225'.
This configuration exists in the base workspace which I am loading on to each worker. Any thoughts on what I am doing wrong?
Code:
parfor i=1:length(buildCandidates)
l = load('workspace.mat');
evalin('base',['slbuild(TC',num2str(buildCandidates(i)),')']);
end
Also tried this:
parfor i=1:length(bulidCandidates)
l = load('workspace.mat');
slbuild(['TC',num2str(buildCandidates(i))]);
end

2 commentaires

Sorry, this is a lame answer, but I would contact the Speedgoat people directly. They may have some tips.
James
James le 17 Fév 2021
Thanks for the suggestion. I could reach out to them, but I feel this is really an issue on the MathWorks side because it is building the Simulink Real-Time application. The Speedgoat group generally focuses on the hardware part of the setup.

Connectez-vous pour commenter.

Réponses (1)

I'm not a Simulink expert, so I'm assuming that loading the workspace (which is the same for all?) will introduce, for example, Model_CnfgRef? If so, try this.
...
parfor i=1:length(bulidCandidates)
build_model(bulidCandidates,i)
end
...
function build_model(bulidCandidates,i)
l = load('workspace.mat');
slbuild(['TC',num2str(bulidCandidates(i))]);
end

9 commentaires

Thanks for the response. I tried your suggestion but unfortunately it still fails. I have double checked the ".mat" file that is loaded and it does contain "Model_CnfgRef". Is there a way I can verify the workspace of a worker?
Warning: Unable to find configuration set 'Model_CnfgRef' for the active configuration reference 'Reference'
> In load_system (line 21)
In load_model
In slbuild (line 95)
In parallelBuild>build_model (line 16)
In parallel_function>make_general_channel/channel_general (line 852)
In remoteParallelFunction (line 46)
Error using slbuild_private
Unable to find configuration: 'Model_CnfgRef' referenced by 'TC225'.
Error in sl (line 15)
[varargout{1:nargout}]=feval(varargin{:});
Error in slbuild (line 98)
sl('slbuild_private', mdl, target, varargin{2:end});
Error in parallelBuild>build_model (line 16)
slbuild(['TC' num2str(buildCandidates(i))]);
Error in parallelBuild (line 8)
parfor i=1:2
You can't call whos from within a parfor, but you can call it in the subfunctions. E.g.
function build_model(bulidCandidates,i)
l = load('workspace.mat');
whos
slbuild(['TC',num2str(bulidCandidates(i))]);
end
Keep in mind the way you've written, all variables loaded from workspace will be stored in the variable l. Perhaps written as a subfunction, you just want
function build_model(bulidCandidates,i)
load('workspace.mat');
slbuild(['TC',num2str(bulidCandidates(i))]);
end
It depends if slbuild is looking for the variable l.
Yes you beat me to responding. I added whos and realized my mistake. I don't want the workspace saved in variable l. I added this because of a "transparency" warning not realizing its effect. So I modified the subfunction to how you have it, and verified through "whos" that Model_CnfgRef exists in the workspace.
function build_model(buildCandidates,i)
load('workspace.mat');
whos
slbuild(['TC' num2str(buildCandidates(i))]);
end
I also tried simplifing the code to just build two models in parallel. As a long shot, I attached both models explicitly even though I believed the models were already accessible by pool the pool workers. It did not change the end outcome. It is obviously not having a problem finding the model file because slbuild is able to open it and know it contains a reference configuration.
poolobj = gcp;
addAttachedFiles(poolobj,{['TC' num2str(buildCandidates(1))] ['TC' num2str(buildCandidates(2))]});
parfor i=1:2
build_model(buildCandidates,i)
end
So now the parallel worker is:
  1. Accessing the model from the client
  2. Has the same workspace as the client
  3. Has the same path as the client
Why is it still unable to build on the remote worker?
Just to clarify terms here, the workers are not accessing the model from the client. The workers are their own standalone process. parfor will push to each of them everything they need to run, include code and data.
The files that you are attaching, are those Simulink models?
What error is being thrown or process that is failing that indicates that the models aren't getting built on the workers?
James
James le 18 Fév 2021
Modifié(e) : James le 18 Fév 2021
Thanks for the clarification. The files I attached are simulink models, but I don't think I needed to attach them becuase there was no error saying the workers could not access the files. I receive the same error below ether way. Here is the error I receive with the latest code:
Warning: Unable to find configuration set 'Model_CnfgRef' for the active configuration reference 'Reference'
> In load_system (line 21)
In load_model
In slbuild (line 95)
In parallelBuild>build_model (line 19)
In parallel_function>make_general_channel/channel_general (line 852)
In remoteParallelFunction (line 46)
Error using slbuild_private
Unable to find configuration: 'Model_CnfgRef' referenced by 'TC225'.
Error in sl (line 15)
[varargout{1:nargout}]=feval(varargin{:});
Error in slbuild (line 98)
sl('slbuild_private', mdl, target, varargin{2:end});
Error in parallelBuild>build_model (line 19)
slbuild(['TC' num2str(buildCandidates(i))]);
Error in parallelBuild (line 10)
parfor i=1:2
Here is a snipit of the "whos" output from the first worker that shows Model_CnfgRef exists in the worker's workspace.
parallelBuild
Warning: Files that have already been attached are being ignored. To see which files are attached see the 'AttachedFiles' property of the parallel pool.
Name Size Bytes Class Attributes
ModelVariant 1x1 552 struct
BuildIndices 1x34 272 double
Comms 1x1 10712 struct
ModelLatencies 1x1 5336 struct
ModelSensorOverrideLimits 1x1 1840 struct
Model_CnfgRef 1x1 Simulink.ConfigSet
Model_CnfgRef_HIL 1x1 Simulink.ConfigSet
I wonder where Simulink is looking for Model_CnfgRef. Maybe it's looking for it in the base workspace, not the caller's workspace? Can the model be set to look for it in the caller's workspace? This is where I thin out with Simulink. Might need to have someone else jump in (or contact Technical Support).
James
James le 23 Fév 2021
Thanks for the help Raymond. I'll reach out to support unless someone else can jump in.
Jon Lobo
Jon Lobo le 19 Déc 2022
Hi James,
I'm going to reopen this thread if thats ok. I worked on something similar for another customer and have a few tips for how to get this to work.
  • Use projects if you aren't already.
  • I highly recommend using data dictionaries as well because relying on base workspace is difficult to debug in parallel workers.
  • Ultimtaely, the first two bullets are because each worker needs to know everything. It's significantly easier if each worker just needs to open a project.
  • I recommend using parfeval rather than parfor. parfeval will have your workers work on the builds while enabling you to continue to do things in MATLAB desktop.
  • Lastly, having each worker build in the same folder is risky as each worker will need access to some common files during code generation and compilation. I find it better to use Simulink.filegencontrol and have each worker do a build in their own directory so they can work in isolation.
Based on the type of problem and your other posts, I'm assuming this is all part of a Simulink Test and Simulink Real-Time workflow.
From the fields in the post, I thikn you are using R2019b. I have an example for using parallel computing toolbox to build all external test harnesses used in a test suite. The code queries the test suite to identfy the models it needs to build, builds the first one in MATLAB desktop and builds the rest using parfeval. The idea is that once the model required by first test is built, you can start running the tests in Simulink test while the other models build.
Please let me know if this is of interest and I can post the example here. Likewise, if you need this in a new release, please let me know and I can update it.
-Jon
James
James le 30 Déc 2022
Hi Jon,
I appreciate the reply. I would be interested in seeing your example if you have it.
Thanks!
James

Connectez-vous pour commenter.

Catégories

En savoir plus sur Test Model Components dans Centre d'aide et File Exchange

Question posée :

le 17 Fév 2021

Commenté :

le 30 Déc 2022

Community Treasure Hunt

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

Start Hunting!

Translated by