static uint[][] HistogramByteComponentsSseParInner(int[] inArray, Int32 l, Int32 r, int parallelThreshold = 16 * 1024) { const int numberOfBins = 256; const int numberOfDigits = sizeof(uint); uint[][] countLeft = null; uint[][] countRight = null; if (l > r) // zero elements to compare { countLeft = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) { countLeft[i] = new uint[numberOfBins]; } return(countLeft); } if ((r - l + 1) <= parallelThreshold) { countLeft = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) { countLeft[i] = new uint[numberOfBins]; } uint[] countLeft0 = countLeft[0]; uint[] countLeft1 = countLeft[1]; uint[] countLeft2 = countLeft[2]; uint[] countLeft3 = countLeft[3]; var union = new Algorithm.Int32ByteUnion(); for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { union.integer = inArray[current]; countLeft0[union.byte0]++; countLeft1[union.byte1]++; countLeft2[union.byte2]++; countLeft3[((uint)inArray[current] >> 24) ^ 128]++; } return(countLeft); } int m = (r + l) / 2; Parallel.Invoke( () => { countLeft = HistogramByteComponentsSseParInner(inArray, l, m, parallelThreshold); }, () => { countRight = HistogramByteComponentsSseParInner(inArray, m + 1, r, parallelThreshold); } ); // Combine left and right results for (int i = 0; i < numberOfDigits; i++) { Addition.AddToSse(countLeft[i], countRight[i]); } return(countLeft); }
public static uint[][] HistogramByteComponentsSsePar(long[] inArray, Int32 l, Int32 r) { const int numberOfBins = 256; const int numberOfDigits = sizeof(ulong); uint[][] countLeft = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) { countLeft[i] = new uint[numberOfBins]; } if (l > r) // zero elements to compare { return(countLeft); } if ((r - l + 1) <= ThresholdByteCount) { var union = new Algorithm.Int64ByteUnion(); for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { union.integer = inArray[current]; countLeft[0][union.byte0]++; countLeft[1][union.byte1]++; countLeft[2][union.byte2]++; countLeft[3][union.byte3]++; countLeft[4][union.byte4]++; countLeft[5][union.byte5]++; countLeft[6][union.byte6]++; countLeft[7][((ulong)inArray[current] >> 56) ^ 128]++; } return(countLeft); } int m = (r + l) / 2; uint[][] countRight = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) { countRight[i] = new uint[numberOfBins]; } Parallel.Invoke( () => { countLeft = HistogramByteComponentsPar(inArray, l, m); }, () => { countRight = HistogramByteComponentsPar(inArray, m + 1, r); } ); // Combine left and right results for (int i = 0; i < numberOfDigits; i++) { Addition.AddToSse(countLeft[i], countRight[i]); } return(countLeft); }