public void RunSequence(ITime triggerTime) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Parallel execution feature disabled."; _runListener.OnEvent(theEvent); /* try find edge model and trigger them first, is possible */ int edgeModel = 0; foreach (Model uimodel in _models) { if (!isModelEngineComponent(uimodel.LinkableComponent)) { continue; } int outDegree = 0; LinkableRunEngine runEngine = (LinkableRunEngine)uimodel.LinkableComponent; foreach (ILink link in runEngine.GetProvidingLinks()) { if (isModelEngineComponent(link.TargetComponent)) { outDegree++; } } theEvent = new Event(EventType.Informative); theEvent.Description = "Out degree of " + uimodel.ModelID + " is " + outDegree + "."; _runListener.OnEvent(theEvent); if (outDegree == 0) { runEngine.RunToTime(triggerTime, -1); edgeModel++; } } /* no edge model was found, perhaps the composition is combined with circles */ if (edgeModel == 0) { theEvent = new Event(EventType.Informative); theEvent.Description = "No edge model found, try invoke all of them."; _runListener.OnEvent(theEvent); foreach (Model uimodel in _models) { if (!isModelEngineComponent(uimodel.LinkableComponent)) { continue; } LinkableRunEngine runEngine = (LinkableRunEngine)uimodel.LinkableComponent; runEngine.RunToTime(triggerTime, -1); } } }
private void scheduleAggressive(ITime triggerTime) { List <List <Model> > orders; lock (this) { orders = getTopologicalOrder(_queueModels); } if (orders.Count > 0) { List <Model> tier = orders[0]; foreach (Model model in tier) { if (!isModelEngineComponent(model.LinkableComponent)) { continue; } lock (this) { if (_runningModels.Contains(model)) { continue; } _runningModels.Add(model); } Event theEvent = new Event(EventType.Informative); theEvent.Description = "Triggering model: " + model.ModelID; _runListener.OnEvent(theEvent); LinkableRunEngine runEngine = (LinkableRunEngine)model.LinkableComponent; new Thread(new ThreadStart(delegate() { runEngine.RunToTime(triggerTime, -1); lock (this) { _runningModels.Remove(model); _queueModels.Remove(model); } _s.Release(); })).Start(); } } }
private void runStandardParallel(ITime triggerTime) { List <Thread> threads = new List <Thread>(); List <Model> uimodels = new List <Model>(_models); List <List <Model> > orders; while ((orders = getTopologicalOrder(uimodels)).Count > 0) { List <Model> tier = orders[0]; string modelIds = ""; foreach (Model uimodel in tier) { modelIds += uimodel.ModelID + ", "; } Event theEvent = new Event(EventType.Informative); theEvent.Description = "Tier models: " + modelIds; _runListener.OnEvent(theEvent); foreach (Model uimodel in tier) { if (!isModelEngineComponent(uimodel.LinkableComponent)) { continue; } LinkableRunEngine runEngine = (LinkableRunEngine)uimodel.LinkableComponent; Thread th = new Thread(new ThreadStart(delegate() { runEngine.RunToTime(triggerTime, -1); })); th.Start(); threads.Add(th); uimodels.Remove(uimodel); } foreach (Thread th in threads) { th.Join(); } threads.Clear(); } }