Is it possible to use SimBiology model objects with the Parallel Computing Toolbox?

4 visualizaciones (últimos 30 días)
I am trying to use some SimBiology functionalities with the Parallel Computing Toolbox. Is this possible?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 13 de Sept. de 2019
Editada: MathWorks Support Team el 12 de Sept. de 2019
Starting MATLAB R2019b, SimBiology model objects can directly be used with the Parallel Computing Toolbox.
If you are using a version prior to R2019b, please refer to the information below.
In MATLAB R2019a and previous releases, there are two issues when using SimBiology functionalities in conjunction with the Parallel Computing Toolbox:
1.SimBiology needs to load relevant libraries to be able to identify the model object as such when passed via a task.
As a workaround:
a. When using the Parallel Computing Toolbox JobManager, execute the following code:
matlabpool
pctRunOnAll(sbioroot)
Note that if you are using a remote Job Manager you will need to make all of the SimBiology model files accessible to the workers by using the following workflow:
matlabpool('open', 'FileDependencies', {'filename.sbproj'})
pctRunOnAll(sbioroot)
This will load the necessary SimBiology libraries. Since with the Job Manager the workers are perpetually open, you only need to do this once. However if any of the workers are restarted or new workers are install, you need to run this again.
b. If using a 3rd party scheduler our or using local scheduler on a single machine, you can define a jobStartup.m file that contains the SBIOROOT command. This will run on the workers every time a new job is run. In the case of the 3rd party or local scheduler, workers are started for every job and do not remain open across jobs. This MATLAB file is similar to the Startup.m file for serial MATLAB.
At installation, jobStartup.m is located at
matlabroot/toolbox/distcomp/user/jobStartup.m
You can define this file in your relevant configuration settings, so that it can get passed with your job and does not need to reside permanently on your cluster.
2. Additionally the functionality PARFOR does not recognize the current object system used to define model objects in SimBiology. Therefore, when distributing the workspace to the workers, the model object gets passed as an empty array.
As a workaround, load the project once per worker within the PARFOR loop. The following function saves it as a persistent variable and only loads the project if it has not been opened before on that worker. This can be altered to pass in the name of the proj file.
Therefore, the overhead associated with loading the model is limited. As a side note: One cannot load variables directly into the PARFOR workspace, so this must be done as a function. The same method is used for all schedulers.
>> m1 = loadSimBiologyModel('myexamplefile.sbproj');
function m2 = loadSimBiologyModel(filename)
% Make m1 a persistent variable so that it does not
% need to be loaded each time
% Load m1 in if it has not been loaded in yet
% Copyright 2008 MathWorks, Inc.
persistent m1
if isempty(m1)
sbioloadproject filename m1 ;
m2 = m1;
% disp('loading')
else
m2 = m1;
% disp('already loaded')
end
end

Más respuestas (0)

Categorías

Más información sobre Extend Modeling Environment en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by