当前位置: 首页>>代码示例>>Python>>正文


Python History.logPower方法代码示例

本文整理汇总了Python中history.History.logPower方法的典型用法代码示例。如果您正苦于以下问题:Python History.logPower方法的具体用法?Python History.logPower怎么用?Python History.logPower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在history.History的用法示例。


在下文中一共展示了History.logPower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Simulator

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import logPower [as 别名]

#.........这里部分代码省略.........
				job.status = Job.Status.SUCCEEDED
				# Update queues
				self.jobsQueue.remove(job.jobId)
				self.jobsDone.append(job.jobId)
				# Log
				self.history.logJob(job)
			
			# Check which nodes are available to run tasks
			# =====================================================
			# Maps
			while self.mapQueued()>0 and self.getIdleNodeMap() != None:
				# Get a map that needs to be executed and assign it to a node
				idleNode = self.getIdleNodeMap()
				# TODO policy to decide when to approximate
				#mapAttempt = self.getMapTask(approx=True if self.getNodesUtilization() > 1.8 else False)
				mapAttempt = self.getMapTask()
				mapAttempt.start = self.t
				if mapAttempt.getJob().isMapDropping():
					mapAttempt.drop()
					mapAttempt.finish = self.t
					mapAttempt.approx = False
					completedJobs += mapAttempt.getJob().dropAttempt(mapAttempt)
					# Log
					self.history.logAttempt(mapAttempt)
				else:
					# Start running in a node
					idleNode.assignMap(mapAttempt)
			# Reduces
			while self.redQueued()>0 and self.getIdleNodeRed() != None:
				# Get a map that needs to be executed and assign it to a node
				idleNode = self.getIdleNodeRed()
				redAttempt = self.getRedTask()
				redAttempt.start = self.t
				if redAttempt.getJob().isRedDropping():
					redAttempt.drop()
					redAttempt.finish = self.t
					# Log
					self.history.logAttempt(redAttempt)
				else:
					idleNode.assignRed(redAttempt)
			
			# Node management
			# =====================================================
			# Check if we need less nodes. Idle nodes.
			if self.nodeManagement:
				lessNodes = 0
				lessNodes = min(len(self.getIdleNodesMap()), len(self.getIdleNodesRed()))
				# Check if we need more nodes. Size of the queues.
				moreNodes = 0
				if lessNodes == 0:
					moreNodesMaps = math.ceil(1.0*self.mapQueued() / 3) - self.getWakingNodes()
					moreNodesReds = math.ceil(self.redQueued() / 1) - self.getWakingNodes()
					moreNodes = max(moreNodesMaps, moreNodesReds, 0)
				# Change node status
				for node in self.nodes.values():
					if node.status == 'ON' and not self.isNodeRequired(node.nodeId) and lessNodes > 0:
						lessNodes -= 1
						seconds = node.timeSleep
						if isRealistic():
							seconds = random.gauss(seconds, 0.1*seconds) #+/-10%
						node.status = 'SLEEPING-%d' % seconds
						self.history.logNodeStatus(self.t, node)
					elif node.status == 'SLEEP' and moreNodes > 0:
						moreNodes -= 1
						seconds = node.timeWake
						if isRealistic():
							seconds = random.gauss(seconds, 0.1*seconds) #+/-10%
						node.status = 'WAKING-%d' % seconds
						self.history.logNodeStatus(self.t, node)
					# Transition status
					elif node.status.startswith('SLEEPING-'):
						seconds = int(node.status[len('SLEEPING-'):]) - 1
						if seconds <= 0:
							node.status = 'SLEEP'
							self.history.logNodeStatus(self.t, node)
						else:
							node.status = 'SLEEPING-%d' % seconds
					elif node.status.startswith('WAKING-'):
						seconds = int(node.status[len('WAKING-'):])   - 1
						if seconds <= 0:
							node.status = 'ON'
							self.history.logNodeStatus(self.t, node)
						else:
							node.status = 'WAKING-%d' % seconds
			# Account for power
			power = 0.0
			for node in self.nodes.values():
				power += node.getPower()
			self.history.logPower(self.t, power)
			
			self.energy += 1.0*power # s x W = J
			
			# Progress to next period
			self.t += self.STEP
		
		# Log final output
		if self.logfile != None:
			self.history.close()
			viewer = HistoryViewer(self.history.getFilename())
			viewer.generate()
开发者ID:,项目名称:,代码行数:104,代码来源:


注:本文中的history.History.logPower方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。