Is it possible that optimisation using normal for loop gives better result in terms of execution time than parfor?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
I used fmincon solver for optimising the equation
yhat = -(exp(-t./z(1))) + (b.*z(2)) - z(3);
where x are the coefficients to be optimized.
- Fmincon was called in the main function.
- Fmincon calls another function in which there is parafor loop. The parafor loop loads the input parameters(t and b) and ydata(expected o/p samples) and passes these and x to another function where yhat is calculated and returns the sum of square the error (yhat-ydata) . This value is then accumulated over the loop iteration and is returned back for fmincon solver to optimize.
- I have used the same code for optimisation using parfor and for loops and observed that execution time taken for parfor was more by 6s.
Is this because the loop was run only for 3 datasets each containing around 1000 samples?
Thanks Nadia
5 件のコメント
Adam
2016 年 6 月 15 日
It all depends on what the process is and how big is the overhead of transferring data to workers vs just doing the calculation in sequence. There isn't one easy answer so you have to experiment with the case you have. Having to open the parallel pool just adds an extra significant overhead to the time.
As with most parallel processing, it all comes down to how efficiently you do the parallelisation and how much processing you are actually doing. Generally there will be some crossover point beyond which parallel processing is faster and below which it isn't worth the overhead.
回答 (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!