Can we use 'parfor' in user defined function?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohsin Shah
am 6 Aug. 2017
Kommentiert: Mohsin Shah
am 7 Aug. 2017
Hello, Can we use 'parfor' in used defined functions? I want to use parfor in user defined functions to improve the speed of my code but its not working. Is there any way we can use it?
3 Kommentare
Walter Roberson
am 6 Aug. 2017
That use of parfor is not permitted because the output would depend upon which iteration ran last. You need either assign to an indexed variable or you need to use a reduction variable (for example totaling the values of the individual iterations)
Akzeptierte Antwort
Walter Roberson
am 6 Aug. 2017
Yes, for sure you can, provided that you have the parallel computing toolbox installed and licensed
4 Kommentare
Walter Roberson
am 7 Aug. 2017
function y = function_name(p)
t = 0;
parfor k = 1 : length(p)
t = t + p(k);
end
y = t;
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!