How does a local parpool manage path per worker?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dinesh
le 19 Déc 2024
Réponse apportée : Edric Ellis
le 23 Déc 2024
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?
0 commentaires
Réponse acceptée
Edric Ellis
le 23 Déc 2024
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!