Data extraction after parallel computing
8 ビュー (過去 30 日間)
古いコメントを表示
I have three functions (fun1, fun2, fun3) to run in parallel (parfor command). Each of this function has three array input (array1,array2, array3), and has three output arrays (Out1,Out2,Out3).
My question is: how can I extract each of the output array of each function after running the parfor command?
The starting code is the following, but I cannot extract the output data for each function.
funcList = {@fun1, @fun2, @fun3};
dataList = {array1,array2, array3; array1,array2, array3; array1,array2, array3}; %# or pass file names
parfor idx = 1 : length(funcList)
result{idx} = funcList{idx}(dataList{idx,:});
end
Thank you in advance
0 件のコメント
回答 (1 件)
Chris
2022 年 10 月 6 日
編集済み: Chris
2022 年 10 月 6 日
To debug a parfor loop, first remove the par and try to run it as a normal loop.
It's possible something in your funcList is not capable of operating across three arrays at once.
If you are trying to apply each function to each array separately, you need 9 outputs for the code above. In that case, something like the following might work:
funcList = {@(x) sum(x,'all'), @(x) prod(x,'all'), @(x) std(x,[],'all')}
dataList = {magic(3),magic(4),magic(5)}
% Precalculate/preallocate things where it makes sense
nd = numel(funcList)*numel(dataList);
arrayidx = rem((1:nd)-1,numel(funcList))+1
funidx = floor(((1:nd)-1)./numel(funcList))+1
results = cell(numel(funcList),numel(dataList));
parfor idx = 1:nd
results{idx} = funcList{funidx(idx)}(dataList{arrayidx(idx)});
end
results
1 件のコメント
Chris
2022 年 10 月 6 日
I would caution you against accessing files on disk in a parfor loop, though. That may not be possible, as a hard drive can't read multiple locations at once.
参考
カテゴリ
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!