/// <summary> /// Based on the selected radiobutton, call the appropriate unmanaged sort. /// </summary> private void ExecuteSort() { switch (sortType) { case SortSelection.StdSort: { stdSortTime = timeTaken = Sorters.native_sort((int)SortSelection.StdSort, fillArray, dimX * dimY, concurrency, comparatorSize); } break; case SortSelection.PplParallelSort: { pplParallelSortTime = timeTaken = Sorters.native_sort((int)SortSelection.PplParallelSort, fillArray, dimX * dimY, concurrency, comparatorSize); } break; case SortSelection.PplParallelBufferedSort: { pplParallelBufferedSortTime = timeTaken = Sorters.native_sort((int)SortSelection.PplParallelBufferedSort, fillArray, dimX * dimY, concurrency, comparatorSize); } break; case SortSelection.PplParallelRadixSort: { pplParallelRadixSortTime = timeTaken = Sorters.native_sort((int)SortSelection.PplParallelRadixSort, fillArray, dimX * dimY, concurrency, comparatorSize); } break; } Thread.Sleep(1000); //Without explicit long sleep, there seems to be an rendering update issue. done = true; }
/// <summary> /// Resets the drawing area according to the Data Type selected /// This internally may call into native std sort /// Note: The pixels are gray-scaled for better/clearer effects /// </summary> private void ResetFill() { int width = dimX; int height = dimY; int rawStride = (width * pf.BitsPerPixel + 7) / 8; fillArray = new byte[rawStride * height]; switch (dataType) { case DataTypeSelection.Random: { //Fill the drawing area with random pixels Random rnd = new Random(100); for (int i = 0, index = 0; i < dimX; ++i) { for (int j = 0; j < dimY; ++j) { byte r = (byte)rnd.Next(256); fillArray[index++] = r; fillArray[index++] = r; fillArray[index++] = r; fillArray[index++] = 255; } } } break; case DataTypeSelection.PreSorted: { //Fill the drawing area with presorted pixels Random rnd = new Random(100); for (int i = 0, index = 0; i < dimX; ++i) { for (int j = 0; j < dimY; ++j) { byte r = (byte)rnd.Next(256); fillArray[index++] = r; fillArray[index++] = r; fillArray[index++] = r; fillArray[index++] = 255; } } Sorters.native_sort((int)SortSelection.StdSort, fillArray, dimX * dimY, 1, 0); } break; case DataTypeSelection.NearlySorted: { //Fill the drawing area with nearly sorted (99% sorted) pixels Random rnd = new Random(100); for (int i = 0, index = 0; i < dimX; ++i) { for (int j = 0; j < dimY; ++j) { byte r = (byte)rnd.Next(256); fillArray[index++] = r; fillArray[index++] = r; fillArray[index++] = r; fillArray[index++] = 255; } } Sorters.native_sort((int)SortSelection.StdSort, fillArray, dimX * dimY, 1, 0); for (int i = 0; i < (fillArray.Length * 0.01); ++i) { int rndElem1 = 4 + rnd.Next(fillArray.Length - 9); rndElem1 -= rndElem1 % 4; int rndElem2 = 4 + rnd.Next(fillArray.Length - 9); rndElem2 -= rndElem2 % 4; for (int j = 0; j < 4; ++j) { byte temp = fillArray[rndElem1 + j]; fillArray[rndElem1 + j] = fillArray[rndElem2 + j]; fillArray[rndElem2 + j] = temp; } } } break; case DataTypeSelection.Sawtooth: { //Fill the drawing area with pixels representing a sawtooth int toothSize = fillArray.Length / (concurrency * 4); byte[] tempArray = new byte[toothSize * 4]; Random rnd = new Random(4); for (int i = 0, index = 0; i < toothSize; ++i) { byte r = (byte)rnd.Next(256); tempArray[index++] = r; tempArray[index++] = r; tempArray[index++] = r; tempArray[index++] = 255; } Sorters.native_sort((int)SortSelection.StdSort, tempArray, (dimX * dimY) / concurrency, 1, 0); for (int i = 0; i < concurrency; ++i) { Array.Copy(tempArray, 0, fillArray, i * tempArray.Length, tempArray.Length); } } break; } }