Can we use 'parfor' in user defined function?
7 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2017 年 8 月 6 日
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)
採用された回答
Walter Roberson
2017 年 8 月 6 日
Yes, for sure you can, provided that you have the parallel computing toolbox installed and licensed
4 件のコメント
Walter Roberson
2017 年 8 月 7 日
function y = function_name(p)
t = 0;
parfor k = 1 : length(p)
t = t + p(k);
end
y = t;
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!