示例#1
0
文件: coord.py 项目: fredvdd/Swan
  def birth(self, n, actors, lower, upper):

    theatres = TheatreList().theatres()
    
    timer = WallClockTimer().start()
    
    h = (upper - lower) / float(n)
    work_per_actor = n / actors
    
    workers = []
    for i in range(0, actors):
      theatre = theatres[i % len(theatres)]
      start =  (work_per_actor * i) + 1
      end = start + work_per_actor
      workers.append(TrapWorker(theatre, lower, h, start, end))
    
    result = sum([worker.result() for worker in workers])
    
    timer.stop()
   
    print "%s&%s&%s\\\\" % (n,result, timer.elapsed_seconds())
    
    [worker.kill() for worker in workers]
    
    die()
示例#2
0
文件: ring.py 项目: fredvdd/Swan
class StartNode(MobileActor):

  def birth(self, n, loops):
    self.n = n
    self.max_loops = loops
    self.loops = 0
    
    self.clock = WallClockTimer().start()
    next = self
    for i in range(0, n):
      next = RingNode(next)  
    self.next = next
    next.accept()
  
  def accept(self):
    self.loops += 1
    if self.loops == self.max_loops:
      self.clock.stop()
      elapsed = self.clock.elapsed_seconds()
      print "%s\t\t&%s" % (self.n, elapsed / (self.n*self.max_loops))
    else:
      self.next.accept()