Free cookie consent management tool by TermsFeed Policy Generator

Changeset 268 for trunk


Ignore:
Timestamp:
05/19/08 16:29:44 (17 years ago)
Author:
gkronber
Message:

improved RAM footprint of distributed-engine by serializing only the part of the scope-tree that contains the scope (including sub-scopes) on which a parallel operation 'operates' on. (ticket #153)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DistributedEngine/DistributedEngine.cs

    r255 r268  
    3232using HeuristicLab.PluginInfrastructure;
    3333using System.Windows.Forms;
     34using System.Diagnostics;
    3435
    3536namespace HeuristicLab.DistributedEngine {
     
    9293            WaitHandle[] waithandles = new WaitHandle[compositeOperation.Operations.Count];
    9394            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            }
    94108            // start all parallel jobs
    95109            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);
    98119
    99120            // wait until all jobs are finished
     
    124145    }
    125146
     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
    126193    private void MergeScope(IScope original, IScope result) {
    127194      // merge the results
  • trunk/sources/HeuristicLab.DistributedEngine/JobManager.cs

    r265 r268  
    7777    }
    7878
    79     public WaitHandle BeginExecuteOperation(IOperatorGraph 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);
    8181      byte[] zippedEngine = ZipEngine(engine);
    8282      Guid currentEngineGuid = Guid.Empty;
  • trunk/sources/HeuristicLab.Grid/ProcessingEngine.cs

    r219 r268  
    3939    }
    4040
    41     public ProcessingEngine(IOperatorGraph graph, IScope globalScope, AtomicOperation initialOperation)
     41    public ProcessingEngine(IScope globalScope, AtomicOperation initialOperation)
    4242      : base() {
    4343      this.initialOperation = initialOperation;
    4444      myGlobalScope = globalScope;
    45       myOperatorGraph = graph;
    4645      myExecutionStack.Push(initialOperation);
    4746    }
Note: See TracChangeset for help on using the changeset viewer.