def simulate(self): """ Run the actual simulation on the controller. This will simply 'intercept' the call to the original simulate and perform location visualisation when necessary. """ self.checkForTemporaryIrreversible() self.noFinishRing.release() if self.locationCellView: from activityVisualisation import visualizeLocations visualizeLocations(self) # Call superclass (the actual simulation) BaseSimulator.simulate(self) self.prev_termination_time = self.termination_time[0]
def performRelocationsInit(self, relocate): """ Perform the relocations specified in the parameter. Split of from the 'findAndPerformRelocations', to make it possible for other parts of the code to perform relocations too. :param relocate: dictionary containing the model_id as key and the value is the node to send it to """ relocate = { key: relocate[key] for key in relocate if self.model_ids[key].location != relocate[key] and self.model_ids[key].relocatable } if not relocate: return if self.runningIrreversible is not None: self.getProxy(self.runningIrreversible).unsetIrreversible() self.runningIrreversible = None while not self.noFinishRing.acquire(False): if not self.runGVT: self.GVTdone() return time.sleep(0) kernels = {} self.locked_kernels = set() relocation_rules = {} for model_id in relocate: source = self.model_ids[model_id].location destination = relocate[model_id] if source == destination: continue kernels[source] = kernels.get(source, 0) + 1 kernels[destination] = kernels.get(destination, 0) + 1 if kernels[source] == 1: # We are the first to lock it, so actually send the lock self.getProxy(source).requestMigrationLock() if kernels[destination] == 1: # We are the first to lock it, so actually send the lock self.getProxy(destination).requestMigrationLock() relocation_rules.setdefault((source, destination), set()).add(model_id) while relocation_rules: # Busy loop until everything is done # Don't use an iterator, as we will change the list for source, destination in relocation_rules.keys(): if source in self.locked_kernels and destination in self.locked_kernels: models = relocation_rules[(source, destination)] self.getProxy(source).migrateTo(destination, models) del relocation_rules[(source, destination)] kernels[source] -= len(models) kernels[destination] -= len(models) if kernels[source] == 0: self.getProxy(source).migrationUnlock() if kernels[destination] == 0: self.getProxy(destination).migrationUnlock() # OK, now check whether we need to visualize all locations or not if self.locationCellView: visualizeLocations(self) # Possibly some node is now hosting all models, so allow this node to become irreversible for some time. self.checkForTemporaryIrreversible() # Allow the finishring algorithm again self.noFinishRing.release()
def performRelocationsInit(self, relocate): """ Perform the relocations specified in the parameter. Split of from the 'findAndPerformRelocations', to make it possible for other parts of the code to perform relocations too. :param relocate: dictionary containing the model_id as key and the value is the node to send it to """ relocate = {key: relocate[key] for key in relocate if self.model_ids[key].location != relocate[key] and self.model_ids[key].relocatable} if not relocate: return if self.runningIrreversible is not None: self.getProxy(self.runningIrreversible).unsetIrreversible() self.runningIrreversible = None while not self.noFinishRing.acquire(False): if not self.runGVT: self.GVTdone() return time.sleep(0) kernels = {} self.locked_kernels = set() relocation_rules = {} for model_id in relocate: source = self.model_ids[model_id].location destination = relocate[model_id] if source == destination: continue kernels[source] = kernels.get(source, 0) + 1 kernels[destination] = kernels.get(destination, 0) + 1 if kernels[source] == 1: # We are the first to lock it, so actually send the lock self.getProxy(source).requestMigrationLock() if kernels[destination] == 1: # We are the first to lock it, so actually send the lock self.getProxy(destination).requestMigrationLock() relocation_rules.setdefault((source, destination), set()).add(model_id) while relocation_rules: # Busy loop until everything is done # Don't use an iterator, as we will change the list for source, destination in relocation_rules.keys(): if source in self.locked_kernels and destination in self.locked_kernels: models = relocation_rules[(source, destination)] self.getProxy(source).migrateTo(destination, models) del relocation_rules[(source, destination)] kernels[source] -= len(models) kernels[destination] -= len(models) if kernels[source] == 0: self.getProxy(source).migrationUnlock() if kernels[destination] == 0: self.getProxy(destination).migrationUnlock() # OK, now check whether we need to visualize all locations or not if self.locationCellView: visualizeLocations(self) # Possibly some node is now hosting all models, so allow this node to become irreversible for some time. self.checkForTemporaryIrreversible() # Allow the finishring algorithm again self.noFinishRing.release()