Pass two .mat files into a function withing a paralel loop
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Swastik Sarkar
2024년 11월 29일 11:23
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!