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!