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
Nadia A
Nadia A 2016년 6월 15일
So incases where a parallel pool is already open and the quantity of data being used is less, parfor is effective than for. Is it?
Adam
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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by