Under what circumstance, mex-version of lsqcurvefit run slower than m-code of lsqcurvefit?

조회 수: 2 (최근 30일)
I converted a function to mex using Coder, which contains lsqcurvefit() to get some speedup. But this mex-version is slower than m-code.
function fit_param_mcode()
param = lsqcurvefit(@obj_fun)
end
% This take 1.6s and 1.5s was spent on objective evaluation
function fit_param_partial_mex()
param = lsqcurvefit(@obj_fun_mex) % only the obj_fun is mex
end
% This full mex version is converted from fit_param_mcode().
% This take 2.6s and 1.5 was spent on objective evaluation, meaning the
% rest 1.1s is spent on mex-version of lsqcurvefit().
function fit_param_full_mex()
... % both lsqcurvefit and obj_fun are mex
end
So, in my own case, the two versions take the same time to evaluate obj_fun, but self-time of m-code of lsqcurvefit() is much smaller.
I tried to reproduce the above result using other objective functions, such as exponential decay, sin(), cos(). But none of them reproduce the result, meaning the full-mex version is faster in these cases.
It seems this is related to my obj_fun, because my obj_fun does not have an analytical formula and it is based on simulation. Maybe mex-version of lsqcurvefit() take much time to do sanity checks and these checks are slow in mex.
Do you have any ideas?
  댓글 수: 1
Xingwang Yong
Xingwang Yong 2021년 4월 30일
Does anyone know how to add "Tags" and "Products" after I post this question. I submited it by accident, without choosing related products. The "Edit" button does not help.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by