Can I call functions inside a parfor loop?

4 ビュー (過去 30 日間)
Daniel Mo
Daniel Mo 2016 年 8 月 13 日
編集済み: Thorsten 2016 年 8 月 15 日
Hi all, I am wondering can I call functions inside a parfor loop? For instance, below is a simple example
parfor i=1:10
A(i) = myfunction(i);
end
In fact, `myfunction` in my code is really complicated, it's a self-defined function to find the optimal solutions. So I am wondering, if I put this in the parfor loop, will it affect? Will each loop influence each other in calling a same function? Some may argue that I shouldn't use parfor loop here, but my program runs really slow so that I need to use parallelized code. Thanks in advance.
  1 件のコメント
Pawel Ladosz
Pawel Ladosz 2016 年 8 月 14 日
I don't see how running in parfor loop would cause a problem. I recommend you just try it and compare the two outputs?

サインインしてコメントする。

回答 (1 件)

Thorsten
Thorsten 2016 年 8 月 15 日
編集済み: Thorsten 2016 年 8 月 15 日
If the results of the computations in the loop are independent of each other, you can use parfor.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by