
small multithread errors

ubi
To be a bit more precise: Each x point is the result of the the difference of two different datasets proceeded by the following function.
Threadsafe FUNCTION fitthematrix_realth(srcwv, tmpwv,outwv,row) WAVE srcwv, tmpwv, outwv variable row variable i tmpwv = srcwv[row][p] CurveFit/N/Q/L=100000 /NTHR=1 poly 4, tmpwv /D wave fit_dumper, M_Covar, W_coef, W_fitConstants, W_ParamConfidenceInterval, W_sigma wavestats/Q/M=1 fit_dumper outwv[row] = 0.0009 * V_minRowLoc killwaves/Z fit_dumper, M_Covar, W_coef, W_fitConstants, W_ParamConfidenceInterval, W_sigma END
In the main function the loop which calls the fit procedure looks like, which is basically copy&pasted from the igor help files:
Variable n,actrow,nthreads= ThreadProcessorCount Variable mt= ThreadGroupCreate(nthreads) Variable ttime= stopMSTimer(-2) for(actrow=0;actrow<DimSize(fieldwv,0);) for(n=0;n<nthreads;n+=1) ThreadStart mt,n, fitthematrix_realth(fieldwv, dumper,resultingfield,actrow) actrow+=1 if( actrow >= DimSize(fieldwv,0) ) break endif endfor do variable tgs= ThreadGroupWait(mt,1000) while( tgs != 0 ) endfor variable dummy= ThreadGroupRelease(mt) Variable mt2= ThreadGroupCreate(nthreads) for(actrow=0;actrow<DimSize(zfieldwave,0);) for(n=0;n<nthreads;n+=1) ThreadStart mt2,n, fitthematrix_realth(zfieldwave, dumper,resultingnofield,actrow) actrow+=1 if( actrow >= DimSize(zfieldwave,0) ) break endif endfor do variable tgs2= ThreadGroupWait(mt2,1000) while( tgs != 0 ) endfor dummy= ThreadGroupRelease(mt2)
Where is my error?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 8, 2012 at 10:43 am - Permalink
- Why is tmpwv passed in as an argument? Each thread will overwrite tmpwv - its contents are undefined.
- You reference a wave called fit_dumper. I don't see one being created. Remember that all threads have their own data folder hierarchy, independent from the 'standard' Igor hierarchy.
That said, here's how I would implement it (note - I assume that your output is 1D and that there is one point for each row in the source matrix).
May 8, 2012 at 12:44 pm - Permalink
Great that fixed the problem. Indeed I have to create tmpwv in the thread. However your suggestion seems to be a bit "lighter", I'll give a try.
May 9, 2012 at 02:07 pm - Permalink