Pass two .mat files into a function withing a paralel loop

5 Ansichten (letzte 30 Tage)
omid mousavi
omid mousavi am 7 Mär. 2017
Beantwortet: Swastik Sarkar am 29 Nov. 2024
Hi,
I want to pass two .mat files that include some variables into a function that changes over a parallel loop, but I keep getting this error: An UndefinedFunction error was thrown on the workers for 'temp_ui_exp'. This might be because the file containing 'temp_ui_exp' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
The code is something like the following:
parpool('AttachedFiles',{'temp_UI.mat','bellman7.mat'});
parfor iter=1:20
[output(iter,1)]=myfunction(varlist);
end
Any help is much appreciated.

Antworten (1)

Swastik Sarkar
Swastik Sarkar am 29 Nov. 2024
I assume that temp_ui_exp is a constant stored in the MAT files attached during the creation of parpool, and the function myfunction utilizes it. Consider declaring a parallel pool constant using code similar to the following:
tempUI = parallel.pool.Constant(@() load('temp_UI.mat'));
And pass tempUI into the function and load it's value like tempUI.Value.temp_ui_exp
Pass tempUI into the function and load its value using tempUI.Value.temp_ui_exp
For more information on parallel pool constants, refer to the following MATLAB documentation:
Hope this helps load variables from MAT files onto the workers.

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by