How does a local parpool manage path per worker?

6 ビュー (過去 30 日間)
Dinesh
Dinesh 2024 年 12 月 19 日
回答済み: Edric Ellis 2024 年 12 月 23 日
At present I have a folder in my root working directory that contains functions intended to overload mathematical functions, e.g. sin, cos, exp, etc. This is for automatic differentiation and I'm happy with the implementation.
I use MATLAB Coder to generate C code from some MATLAB code that uses these functions (several models of a physical system), and in code I choose whether to use standard MATLAB math functions or my function overloads by adding or removing the folder containing the overloaded math functions. If I want to code generate all the models, I run a for loop and generate the C code sequentially, and for each iteration I can add the path to the overloaded math function folder and then remove it when I would like automatic differentiation, or choose to not to add it to the path.
I would like to speed up this code generation process by using parfor, however I'm unclear how each worker in a local parpool manages its own path. If I have two code generation processes running in parallel on 2 workers, and the code on one worker manipulates the path through addpath/rmpath does it affect the other worker? Scale this up to > 2 workers where the code on various workers may or may not be manipulating the path to faciliate my function overloading, is there any risk that my code will be generated with the incorrect math functions?

採用された回答

Edric Ellis
Edric Ellis 2024 年 12 月 23 日
Workers in a local parallel pool inherit their MATLAB path (and current working directory) from the MATLAB client. However, if you make modifications to a worker's path directly in some code running in side parfor or parfeval, those changes are not seen by any other workers. I would proceed by writing a function that wraps up the path modifications you need, and uses onCleanup to revert the changes.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing Fundamentals についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by