currentProject() function in Parallel Computing Toolbox

4 次查看(过去 30 天)
I have a workflow that uses the MATLAB project functions to retrieve information from the MATLAB project. I use currentProject() to get the matlab.project.Project object.
I am trying to run this workflow using the Parallel Computing Toolbox, but seems that the MATLAB project is not available in the MATLAB workers.
Tested it using this code:
parpool(2);
Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 2).
spmd
currentProject();
end
Error detected on workers 1 2.

Caused by:
Error using currentProject
No project is currently loaded.
Does the MATLAB project gets transferred into the MATLAB workers, or only the MATLAB path?
Any workaround about how can I pull the Project Reference information in a distributed environment?
Thanks in advance!

采纳的回答

Sean de Wolski
Sean de Wolski 2023-2-14
You can open the project on all workers before the loop with parfevalOnAll.
gcp
rf = currentProject().RootFolder
parfevalOnAll(@()openProject(rf), 0)
parfor ii = 1:4
disp(currentProject().RootFolder)
end
  2 个评论
Isaac De La Cruz
Isaac De La Cruz 2023-2-15
Thanks @Sean de Wolski! This solution works.
Unfortunately for me, the MATLAB projects has a lot of overhead during startup, so I decided to take another approach of storing the information from the MATLAB project before distribution.
Simon
Simon 2024-8-7
I was having a similar issue with a test suite (and runInParallel) That solution works thank you @Sean de Wolski
In the future will this be changed so that the open projects are instantiated on the workers without user input? Or is this the intended behavior?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming Utilities 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by