protected void ComputeParallelUnSufficientThreads(PatternNodePPA node, ResultPPA result, int numThreads) { int[] childrenPerThread = DivideThreadsChildren(node.CountChildren, numThreads); Thread[] threads = new Thread[childrenPerThread.Length - 1]; List <PatternNodePPA> children; node.TryGetChildren(out children); int index = 0; for (int i = 0; i < threads.Length; i++) { int startIndex = index; ResultPPA clone = result.GetClone(); int childrenToThread = childrenPerThread[i]; threads[i] = new Thread(() => ComputeParallelUnSufficientThreadsChildrenProcessing(children, startIndex, childrenToThread, clone)); index += childrenPerThread[i]; } foreach (var thread in threads) { thread.Start(); } ComputeParallelUnSufficientThreadsChildrenProcessing(children, index, childrenPerThread[childrenPerThread.Length - 1], result.GetClone()); foreach (var thread in threads) { thread.Join(); } result.FetchDataAllClones(); result.DisposeClones(); }
protected void ComputeParallelSufficientThreads(PatternNodePPA node, ResultPPA result, int numThreads) { int[] numThreadsChildren = ComputeThreadsCountChildren(node.CountChildren, numThreads); Thread[] threads = new Thread[node.CountChildren - 1]; List <PatternNodePPA> children; node.TryGetChildren(out children); for (int i = 0; i < threads.Length; i++) { ResultPPA clone = result.GetClone(); PatternNodePPA child = children[i]; int numThreadsChild = numThreadsChildren[i]; threads[i] = new Thread(() => ComputeParallel(child, clone, numThreadsChild)); } foreach (var thread in threads) { thread.Start(); } ComputeParallel(children[children.Count - 1], result.GetClone(), numThreadsChildren[children.Count - 1]); foreach (var thread in threads) { thread.Join(); } result.FetchDataAllClones(); result.DisposeClones(); }