c# - Is there a way to control spatial/memory locality when using Parallel.For -


I have a large array of unstable floats - the array length is 40,000,000 to measure this array, I thought it To use Parallel.For () would be more demonstrative. Here is the sequential version of the loop for the scales of data: + offset; }

here parallel. Foro () has been changed for example:

  Parallel.For (0, rawData length, i = & gt; {scaladata [i] = roradata [i] * Scale + offset;});   

But the performance is bad! My guess is, seeing the index / thread combinations, it is that is parallel FO () In this way memory is being accessed due to additional paging, to test this principle, I have the parallel. Tried to use as invoke () :

  Parallel.Invoke ((=) => {for (int i = 0; i & lt; 10000000; I ++) {dst [i] = src [i] * scale + offset;}}, () = & gt; (for int i = 10000000; i & lt; 20000000; i ++) {DST [ I] = src [i] * scale + offset;}}, () = & gt; {(int i = 20000000; i & lt; 30000000; i ++) {dst [i] = src [i] * scale + Offset;}}, () = & gt; {(int i = 30000000; i & lt; 40000000; i ++) {dst [i] = src [i] * scale + offset;}},);   

And it performs much better, but I hate the hard-coded nature of this code. I have 4 processors, so this is why IV (4) has given 4 actions.

Is there no way to divide the throdes in such fashion which does not beat the memory?

To obtain the behavior you want without using Parallel.Invoke You can use custom partitioner for Color Administrator is what you want to start.

  var rangepartitioner = Partitioner.Create (0, rawData.Length); Double [] results = new double [rawData.Length]; Parallel.ForEach (Category Segmentation, (Range, LoopState) = & gt; {for (int i = range. ITM1; I and LT; Category.ITM2; I ++) {Scaladata [I] = RowData ] * Scale * offset;}});   

You can create a custom partitioner and overload to adjust the size of the blocks that suits your needs.

Look for an in-depth discussion.

Will this data improve in the area, provided that your array includes price types in which case they will be allocated in the form of blocks of compatible memory This is not the case for reference types. FWIW Tried to fix the terrain properly, but there was no surprising improvement. I came to the conclusion that potentially there is a possibility of access to other memory from CLR and this can result in difficulties to understand memory access patterns

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -