public ResultPPA Compute(IPermutationsCollection avoidedPatterns, int maximalLengthAvoiders, ResultPPA result, int numThreads) { PatternNodePPA node = computationSequential.Compute(avoidedPatterns, maximalLengthAvoiders, avoidedPatterns.LengthLongestPermutation - 1, result); return(computationTreeTraverse.Compute(node, avoidedPatterns, maximalLengthAvoiders, result, numThreads, avoidedPatterns.LengthLongestPermutation - 1)); }
public override bool TryProcessNodeChildren(PatternNodePPA nodePpa) { List <PatternNodePPA> children; if (nodePpa.TryGetChildren(out children)) { ProcessNodes(children); return(true); } return(false); }
protected void ComputeStepProcessChildren(PatternNodePPA node, ResultPPA result) { PatternNodePPA parent = node.Parent; List <PatternNodePPA>[] descendants; parent.TryGetDescendants(out descendants); List <PatternNodePPA> nodes = descendants[node.PositionPrecedingLetters(node.Permutation.Length - 1)]; foreach (var nodeProcessed in nodes) { result.TryProcessNodeChildren(nodeProcessed); } }
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 ComputeParallelHandler(PatternNodePPA node, ResultPPA result, int numThreads) { if (depthComputed > node.Permutation.Length + descendantsDepth && node.CountChildren > 0) { if (numThreads == 1) { ComputeNonParallel(node, result); } else { if (numThreads < node.CountChildren) { ComputeParallelUnSufficientThreads(node, result, numThreads); } else { ComputeParallelSufficientThreads(node, result, numThreads); } node.DisposeChildren(); node.DisposeDescendants(); } } }
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(); }
protected void ComputeParallel(PatternNodePPA node, ResultPPA result, int numThreads) { ComputeStep(node, result); ComputeParallelHandler(node, result, numThreads); }
public abstract void ProcessNode(PatternNodePPA nodePpa);
public abstract bool TryProcessNodeChildren(PatternNodePPA nodePpa);