One question about multithread and fitting with implicit function

I tried to fit the data with some implicit function, in fact, an ellipse function with multithread capability built in FuncFit and found some things I did not understand. The functions are shown as followed:
...
ThreadSafe Function Func_Ellipse(Coefs, x, y) : FitFunc

    Wave Coefs  // Coefs[0] = theta, Coefs[1] = x_0, Coefs[2] = y_0, Coefs[3] = a, Coefs[4] = b,
    Variable x, y

    Return ((x - Coefs[1]) / Coefs[3]) ^ 2 + ((y - Coefs[2]) / Coefs[4]) ^2 + cos(Coefs[0]) ^ 2 - 2 * cos(Coefs[0]) * (x - Coefs[1]) * (y - Coefs[2]) / (Coefs[3] * Coefs[4]) - 1

End

Function Fit_ellipse(Data_x, Data_y, Coefs_ellipse, Data_fitted_x, Data_fitted_y)

    Wave Data_x, Data_y, Coefs_ellipse, Data_fitted_x, Data_fitted_y

    Variable V_fitOptions=4

    FuncFit /N=1 /NTHR=1 /ODR=3 /Q=1 /W=2 Func_Ellipse, Coefs_ellipse /X={Data_x, Data_y} /XD={Data_fitted_x, Data_fitted_y}

End
...


I found no matter how I set /NTHR=0, 1 or 2, the activity monitor showed 2 cpu cores were mostly occupied. It seemed to me that the multithread was always on but the computation time was quite different for /NTHR=1. If /NTHR=0 or 2, the computation time was more than twice for /NTHR=1. The data points for the fitting was about 25,000. Is there any reason for the phenomenon I observed?
You mention Multithread, but I don't see that in your code. Perhaps I am confused- Multithread is a keyword in Igor that can be used to do a wave assignment using more than one processor for the computations associated with the assignment.

If, in fact, you are using the Multithread keyword in your fitting function, then you should use /NTHR=1. It is a bad idea to use threading inside something that is already threaded. Using /NTHR=0 will cause a normal user-defined fit function to use as many threads as the number of processors available. If you use Multithread inside such a function, then you are using more threads than processors available, and the result is very likely to be a degradation in performance.

The Multithread keyword was added after the threading support for user-defined functions. I should re-visit some of my code, and the documentation to address some of these issues of when it is appropriate to use threading.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
You mention Multithread, but I don't see that in your code. Perhaps I am confused- Multithread is a keyword in Igor that can be used to do a wave assignment using more than one processor for the computations associated with the assignment.

If, in fact, you are using the Multithread keyword in your fitting function, then you should use /NTHR=1. It is a bad idea to use threading inside something that is already threaded. Using /NTHR=0 will cause a normal user-defined fit function to use as many threads as the number of processors available. If you use Multithread inside such a function, then you are using more threads than processors available, and the result is very likely to be a degradation in performance.

The Multithread keyword was added after the threading support for user-defined functions. I should re-visit some of my code, and the documentation to address some of these issues of when it is appropriate to use threading.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


I did not use the keyword "MultiThread" in my fitting function. The function used is just as shown here. That is also why I post here to ask. I did not set MultiThread keyword in my function and only set /NTHR=1 but two cores were mostly fully occupied. Meanwhile, I am confused as well why the result of /NTHR=0 is worse than /NTHR=1.

I am also wondering how I should do write my implicit fitting function in the form of All-at-once?