- Timestamp:
- 05/19/08 16:29:44 (17 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DistributedEngine/DistributedEngine.cs
r255 r268 32 32 using HeuristicLab.PluginInfrastructure; 33 33 using System.Windows.Forms; 34 using System.Diagnostics; 34 35 35 36 namespace HeuristicLab.DistributedEngine { … … 92 93 WaitHandle[] waithandles = new WaitHandle[compositeOperation.Operations.Count]; 93 94 int i = 0; 95 // HACK: assume that all atomicOperations have the same parent scope. 96 // 1) find that parent scope 97 // 2) remove all branches starting from the global scope that don't lead to the parentScope of the parallel operation 98 // 3) keep the branches to 'repair' the scope-tree later 99 // 4) for each parallel job attach only the sub-scope that this operation uses 100 // 5) after starting all parallel jobs restore the whole scope-tree 101 IScope parentScope = FindParentScope(GlobalScope, compositeOperation); 102 List<IList<IScope>> prunedScopes = new List<IList<IScope>>(); 103 PruneToParentScope(GlobalScope, parentScope, prunedScopes); 104 List<IScope> subScopes = new List<IScope>(parentScope.SubScopes); 105 foreach(IScope scope in subScopes) { 106 parentScope.RemoveSubScope(scope); 107 } 94 108 // start all parallel jobs 95 109 foreach(AtomicOperation parOperation in compositeOperation.Operations) { 96 waithandles[i++] = jobManager.BeginExecuteOperation(OperatorGraph, GlobalScope, parOperation); 97 } 110 parentScope.AddSubScope(parOperation.Scope); 111 waithandles[i++] = jobManager.BeginExecuteOperation(GlobalScope, parOperation); 112 parentScope.RemoveSubScope(parOperation.Scope); 113 } 114 foreach(IScope scope in subScopes) { 115 parentScope.AddSubScope(scope); 116 } 117 prunedScopes.Reverse(); 118 RestoreFullTree(GlobalScope, prunedScopes); 98 119 99 120 // wait until all jobs are finished … … 124 145 } 125 146 147 private void RestoreFullTree(IScope currentScope, IList<IList<IScope>> savedScopes) { 148 if(savedScopes.Count == 0) return; 149 IScope remainingBranch = currentScope.SubScopes[0]; 150 currentScope.RemoveSubScope(remainingBranch); 151 IList<IScope> savedScopesForCurrent = savedScopes[0]; 152 foreach(IScope savedScope in savedScopesForCurrent) { 153 currentScope.AddSubScope(savedScope); 154 } 155 savedScopes.RemoveAt(0); 156 RestoreFullTree(remainingBranch, savedScopes); 157 } 158 159 private IScope PruneToParentScope(IScope currentScope, IScope scope, IList<IList<IScope>> prunedScopes) { 160 if(currentScope == scope) return currentScope; 161 if(currentScope.SubScopes.Count == 0) return null; 162 IScope foundScope = null; 163 // try to find the searched scope in all my sub-scopes 164 foreach(IScope subScope in currentScope.SubScopes) { 165 foundScope = PruneToParentScope(subScope, scope, prunedScopes); 166 if(foundScope != null) break; // we can stop as soon as we find the scope in a branch 167 } 168 if(foundScope != null) { // when we found the scopes in my sub-scopes 169 List<IScope> subScopes = new List<IScope>(currentScope.SubScopes); // store the list of sub-scopes 170 prunedScopes.Add(subScopes); 171 // remove all my sub-scopes 172 foreach(IScope subScope in subScopes) { 173 currentScope.RemoveSubScope(subScope); 174 } 175 // add only the branch that leads to the scope that I search for 176 currentScope.AddSubScope(foundScope); 177 return currentScope; // return that this scope contains the branch that leads to the searched scopes 178 } else { 179 return null; // otherwise we didn't find the searched scope and we can return null 180 } 181 } 182 183 private IScope FindParentScope(IScope currentScope, CompositeOperation compositeOperation) { 184 AtomicOperation currentOperation = (AtomicOperation)compositeOperation.Operations[0]; 185 if(currentScope.SubScopes.Contains(currentOperation.Scope)) return currentScope; 186 foreach(IScope subScope in currentScope.SubScopes) { 187 IScope result = FindParentScope(subScope, compositeOperation); 188 if(result != null) return result; 189 } 190 return null; 191 } 192 126 193 private void MergeScope(IScope original, IScope result) { 127 194 // merge the results -
trunk/sources/HeuristicLab.DistributedEngine/JobManager.cs
r265 r268 77 77 } 78 78 79 public WaitHandle BeginExecuteOperation(I OperatorGraph operatorGraph, IScope globalScope, AtomicOperation operation) {80 ProcessingEngine engine = new ProcessingEngine( operatorGraph, globalScope, operation); // OperatorGraph not needed?79 public WaitHandle BeginExecuteOperation(IScope globalScope, AtomicOperation operation) { 80 ProcessingEngine engine = new ProcessingEngine(globalScope, operation); 81 81 byte[] zippedEngine = ZipEngine(engine); 82 82 Guid currentEngineGuid = Guid.Empty; -
trunk/sources/HeuristicLab.Grid/ProcessingEngine.cs
r219 r268 39 39 } 40 40 41 public ProcessingEngine(I OperatorGraph graph, IScope globalScope, AtomicOperation initialOperation)41 public ProcessingEngine(IScope globalScope, AtomicOperation initialOperation) 42 42 : base() { 43 43 this.initialOperation = initialOperation; 44 44 myGlobalScope = globalScope; 45 myOperatorGraph = graph;46 45 myExecutionStack.Push(initialOperation); 47 46 }
Note: See TracChangeset
for help on using the changeset viewer.