public void SortMultipleTimes() { var length01 = 100; var length02 = 1000; var parallelSort = new ParallelSort <DataWithIndex <float> >(); var array01 = SortUtilityTest.GenerateFloatNativeArray(length01, out var inputDeps); var counter01 = new NativeCounter(Allocator.TempJob); inputDeps = parallelSort.Sort(array01, array01.Length, 8, inputDeps); inputDeps = SortUtilityTest.CountSortedData(parallelSort.SortedData.AsDeferredJobArray(), counter01, array01.Length, inputDeps); var array02 = SortUtilityTest.GenerateFloatNativeArray(length02, out var moreFloatsHandle); inputDeps = JobHandle.CombineDependencies(inputDeps, moreFloatsHandle); var counter02 = new NativeCounter(Allocator.TempJob); inputDeps = parallelSort.Sort(array02, array02.Length, 3, inputDeps); inputDeps = SortUtilityTest.CountSortedData(parallelSort.SortedData.AsDeferredJobArray(), counter02, array02.Length, inputDeps); inputDeps.Complete(); var result01 = counter01.Value; var result02 = counter02.Value; counter01.Dispose(); array01.Dispose(); counter02.Dispose(); array02.Dispose(); parallelSort.Dispose(); Assert.True(result01 == length01); Assert.True(result02 == length02); }
static void FloatSort(int length, int processAmount, int concurrentJobs) { var array = SortUtilityTest.GenerateFloatNativeArray(length, out var inputDeps); inputDeps.Complete(); Sort(array, processAmount, concurrentJobs); }
static DataWithIndex <T>[] Sort <T>(NativeArray <DataWithIndex <T> > array, int processAmount, int concurrentJobs) where T : struct, IComparable <T> { var length = array.Length; var timeSpanParallelSort = new TimeSpanParallelSort <DataWithIndex <T> >(); var counter = new NativeCounter(Allocator.TempJob); var cycles = 0; timeSpanParallelSort.Start(array, processAmount, concurrentJobs).Complete(); while (!timeSpanParallelSort.IsComplete) { timeSpanParallelSort.Update().Complete(); cycles++; } SortUtilityTest .CountSortedData(timeSpanParallelSort.SortedData.AsDeferredJobArray(), counter, length, default) .Complete(); var sortedArray = timeSpanParallelSort.SortedData.ToArray(); var result = counter.Value; counter.Dispose(); array.Dispose(); timeSpanParallelSort.Dispose(); Assert.True(result == length); UnityEngine.Debug.Log($"Sorted array in {cycles} cycles"); return(sortedArray); }
static void FloatSort(int length, int concurrentJobs) { var array = SortUtilityTest.GenerateFloatNativeArray(length, out var inputDeps); var parallelSort = new ParallelSort <DataWithIndex <float> >(); var counter = new NativeCounter(Allocator.TempJob); inputDeps = parallelSort.Sort(array, array.Length, concurrentJobs, inputDeps: inputDeps); inputDeps = SortUtilityTest.CountSortedData(parallelSort.SortedData.AsDeferredJobArray(), counter, array.Length, inputDeps); inputDeps.Complete(); var result = counter.Value; counter.Dispose(); array.Dispose(); parallelSort.Dispose(); Assert.True(result == length); }
static DataWithIndex <int>[] IntSort(NativeArray <DataWithIndex <int> > array, int concurrentJobs, JobHandle inputDeps = default) { var length = array.Length; var parallelSort = new ParallelSort <DataWithIndex <int> >(); var counter = new NativeCounter(Allocator.TempJob); inputDeps = parallelSort.Sort(array, length, concurrentJobs, inputDeps); inputDeps = SortUtilityTest.CountSortedData(parallelSort.SortedData.AsDeferredJobArray(), counter, length, inputDeps); inputDeps.Complete(); var sortedArray = parallelSort.SortedData.ToArray(); var result = counter.Value; counter.Dispose(); array.Dispose(); parallelSort.Dispose(); Assert.True(result == length); return(sortedArray); }
static void IntSort(int length, int concurrentJobs) { IntSort(SortUtilityTest.GenerateIntNativeArray(length, out var inputDeps), concurrentJobs, inputDeps); }