0

I have a large single dimension array ful of Zmap data (ea height data) the array is quite huge it consists of 100 measurements samples of an area pixel. I need to process it in several ways, so that another locked bitmap can be corrected. To speed up to processing of this large array I make use of parallel.for

ea:

public void MarkErrorSamples(int[]Depthdata,int lowbound)
{ 
    Parallel.For (0, depthData.Length, sampleN => 
    {
        if(depthData[sampleN] < lowbount) 
        {
            // update redchannel Red value by 20
            int x= xfromLockedmemPos(sampleN); // x value based upon sampleN
            int y =yfromLockedmemPos(sampleN); 
            setpixel(x,y,AddRed((getpixelRed(x,y),20);
        }
    });
}

The above code works but I have some doubts about accessing the depthdata[sampleN] the way I do it now. My concern here is that I think the threads might lock the array with each time a thread is launched to retrieve data from it. So I wonder is above the correct way to work with a 'external block' array data in an Parallel.for

Note that in the above void it is not required change the depthdata itself, only perform action on bitmap (making use of a lockbits bitmap).

DavidG
  • 113,891
  • 12
  • 217
  • 223
user613326
  • 2,140
  • 9
  • 34
  • 63
  • 1
    _My concern here is that I think the threads might lock the array with each time a thread is launched to retrieve data from it_ Not sure if i get your sentence correctly but if the array gets locked for example then this would not be parallel anymore. – M.kazem Akhgary Nov 06 '15 at 13:28
  • 3
    The common consensus seems to be that accessing *different* parts of an array from different threads is not a problem. [Source 1](http://stackoverflow.com/q/2798899/87698), [Source 2](http://stackoverflow.com/a/1460660/87698). – Heinzi Nov 06 '15 at 13:31
  • @ M.kazem Yes i wonder that, nothing else is claiming the array when this function is called. but stll the elements of the array live outside the Parallel.Fro scope. So i wonder if its posible to put in each thread the valeu of depthData[sampleN] – user613326 Nov 06 '15 at 13:33
  • Watch out for [`false sharing`](https://en.wikipedia.org/wiki/False_sharing) which may severely impact a parallel algorithm such as that because of forced processor cache reloads. – Matthew Watson Nov 06 '15 at 13:51
  • Ehm well yes i am woried about access locking , acoording to @Heinz its not a problem, while others write about it. I might even 'batch' the whole dataset in smaller parts, and the let the simple actions run on smaller arrays.. but still i keep myself wondering about: memory locks, arrays and threads. And i dont know how to parse an array into a Parallel for, so that each thread knows which array element to use from scratch. – user613326 Nov 06 '15 at 15:05

0 Answers0