Data extraction after parallel computing
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Chris
le 6 Oct 2022
Modifié(e) : Chris
le 6 Oct 2022
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 commentaire
Chris
le 6 Oct 2022
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.
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!