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!