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

3 ビュー (過去 30 日間)
omid mousavi
omid mousavi 2017 年 3 月 7 日
回答済み: Swastik Sarkar 2024 年 11 月 29 日
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.

回答 (1 件)

Swastik Sarkar
Swastik Sarkar 2024 年 11 月 29 日
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.

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by