I don't have a lot of time but from a quick look at your post:
Think about what happens in your parallel calculation. Igor spawns a bunch of threads and these start crunching away, independently and regardless of what other threads may be doing. This also means that if different threads write to the same memory, each will modify this memory as it pleases and the result is unpredictable. Read the section called "Example atomic operation" here to understand what that means with respect to your problem.
Igor tries to prevent these problems from occurring by giving each thread its own, private data folder hierarchy, such that all waves created by the thread are accessible only by that thread. The exception, of course, are function arguments. In other words, every thread refers to the same "total" wave.
So when you do this:
The result is undefined because multiple threads can modify it simultaneously.
Your only option is to provide each thread with its own copy of total (so if there are 8 threads, create 8 copies of total, all initialized to zero), and to add all of these waves together into the final result after the threads have completed.
Also, the loop in which you call ThreadStart has issues, but I don't have time now so maybe someone else will chip in on that.
ChrLie wrote:
Threadsafe function workerFunc(cube, total, mask, col) wave cube, total, mask variable col variable i for (i=0; i<DimSize(cube, 0);i+=1) if (mask[i][col] ==1) ImageTransform /Beam ={(i), (col)} getBeam cube wave W_Beam total+=W_Beam endif endfor end
Think about what happens in your parallel calculation. Igor spawns a bunch of threads and these start crunching away, independently and regardless of what other threads may be doing. This also means that if different threads write to the same memory, each will modify this memory as it pleases and the result is unpredictable. Read the section called "Example atomic operation" here to understand what that means with respect to your problem.
Igor tries to prevent these problems from occurring by giving each thread its own, private data folder hierarchy, such that all waves created by the thread are accessible only by that thread. The exception, of course, are function arguments. In other words, every thread refers to the same "total" wave.
So when you do this:
total+=W_Beam
The result is undefined because multiple threads can modify it simultaneously.
Your only option is to provide each thread with its own copy of total (so if there are 8 threads, create 8 copies of total, all initialized to zero), and to add all of these waves together into the final result after the threads have completed.
Also, the loop in which you call ThreadStart has issues, but I don't have time now so maybe someone else will chip in on that.