void SelectParallel() { int maxDepth = 0; using (var depths = m_DepthMap.GetValueArray(Allocator.Temp)) { for (int i = 0; i < depths.Length; i++) { maxDepth = math.max(maxDepth, depths[i]); } } var inputStates = new NativeList <int>(1, Allocator.TempJob); inputStates.Add(rootState); var inputBudgets = new NativeList <int>(1, Allocator.TempJob); inputBudgets.Add(1); var outputStateBudgets = new NativeMultiHashMap <int, int>(1, Allocator.TempJob); var selectedUnexpanded = new NativeHashMap <int, byte>(1, Allocator.TempJob); JobHandle jobHandle = default; for (int iteration = 0; iteration <= maxDepth; iteration++) { // Selection job jobHandle = new ParallelSelectionJob <int, int>() { StateDepthLookup = m_DepthMap, StateInfoLookup = m_PlanGraph.StateInfoLookup, ActionInfoLookup = m_PlanGraph.ActionInfoLookup, ActionLookup = m_PlanGraph.ActionLookup, ResultingStateLookup = m_PlanGraph.ResultingStateLookup, StateTransitionInfoLookup = m_PlanGraph.StateTransitionInfoLookup, Horizon = iteration, InputStates = inputStates.AsDeferredJobArray(), InputBudgets = inputBudgets.AsDeferredJobArray(), OutputStateBudgets = outputStateBudgets.AsParallelWriter(), SelectedStateHorizons = m_SelectedStateHorizons.AsParallelWriter(), SelectedUnexpandedStates = selectedUnexpanded.AsParallelWriter(), }.Schedule(inputStates, default, jobHandle);
public IEnumerator TestPerformanceOnLargeGraphBudget10Parallel() { var planGraph = PlanGraphUtility.BuildLattice(10); var nodeCount = planGraph.Size; var depthMap = new NativeHashMap <int, int>(nodeCount, Allocator.TempJob); var queue = new NativeQueue <StateHorizonPair <int> >(Allocator.TempJob); planGraph.GetExpandedDepthMap(0, depthMap, queue); int budget = 10; int size = math.min(budget, depthMap.Count()); UnityEngine.Assertions.Assert.IsTrue(size > 0); var inputStates = new NativeList <int>(size, Allocator.TempJob); inputStates.Add(0); var inputBudgets = new NativeList <int>(size, Allocator.TempJob); inputBudgets.Add(budget); var outputStateBudgets = new NativeMultiHashMap <int, int>(size, Allocator.TempJob); var m_SelectedStateHorizons = new NativeMultiHashMap <int, int>(size, Allocator.TempJob); var m_SelectedUnexpandedStates = new NativeHashMap <int, byte>(size, Allocator.TempJob); // Determine max number of job iterations int maxDepth = 0; using (var depths = depthMap.GetValueArray(Allocator.Temp)) { for (int i = 0; i < depths.Length; i++) { maxDepth = math.max(maxDepth, depths[i]); } } yield return(null); // Set up performance test Measure.Method(() => { JobHandle lastHandle = default; for (int iteration = 0; iteration <= maxDepth; iteration++) { // Selection job lastHandle = new ParallelSelectionJob <int, int> { StateDepthLookup = depthMap, StateInfoLookup = planGraph.StateInfoLookup, ActionInfoLookup = planGraph.ActionInfoLookup, ActionLookup = planGraph.ActionLookup, ResultingStateLookup = planGraph.ResultingStateLookup, StateTransitionInfoLookup = planGraph.StateTransitionInfoLookup, Horizon = iteration, InputStates = inputStates.AsDeferredJobArray(), InputBudgets = inputBudgets.AsDeferredJobArray(), OutputStateBudgets = outputStateBudgets.AsParallelWriter(), SelectedStateHorizons = m_SelectedStateHorizons.AsParallelWriter(), SelectedUnexpandedStates = m_SelectedUnexpandedStates.AsParallelWriter(), }.Schedule(inputStates, default, lastHandle);