Ejemplo n.º 1
0
    def test29(self):

        pool = AsyncRequestsPool()

        x = self.ForTestingInterface()
        y = self.ForTestingInterface()
        sequenced_requests_indices = []
        def next_request(index):
            if index < 4:
                sequenced_requests_indices.append(index)
                return x.sleep.asynchronous(0.5)
            else:
                return None

        request1 = ASyncRequestSequence(next_request)
        request2 = y.sleep.asynchronous(1.0)
        finished_requests = []

        def handle_result(request, index):
            self.assertTrue(request.is_result_available())
            self.assertTrue(request.is_finished)
            finished_requests.append(index)

        pool.add_request(request1, handle_result, [1])
        pool.add_request(request2, handle_result, [2])

        pool.wait()
        self.assertEqual(len(finished_requests), 1)
        self.assertEqual(len(pool), 1)
        self.assertEqual(finished_requests, [2])
        self.assertTrue(len(sequenced_requests_indices) > 0)

        pool.wait()
        self.assertEqual(len(finished_requests), 2)
        self.assertEqual(len(pool), 0)
        x.sleep(0.1)
        self.assertEqual(sequenced_requests_indices, [0, 1, 2, 3])

        self.assertTrue(request1.is_result_available())
        self.assertTrue(request2.is_result_available())

        self.assertEqual(request1.result(), [0, 0, 0, 0])
        self.assertEqual(request2.result(), 0)

        y.stop()
        x.stop()
Ejemplo n.º 2
0
    def __init__(self,hosts=[],channel_type="mpi",preamble=None, retry_jobs=True, 
                   no_wait=True,verbose=True,max_retries=2, use_threading=False):
      self.hosts=[]
      self.job_list=deque()
      self.idle_codes=[]
      self.retry_jobs=retry_jobs
      self.max_retries=max_retries
      self._finished_jobs=deque()
      self.preamble=preamble
      self.pool=AsyncRequestsPool()
      self.number_available_codes=0
      self.number_starting_codes=0
      self.no_wait=no_wait
      self.last_finished_job=None
      self.use_threading=use_threading
      self.verbose=verbose
      if self.verbose:
          print "AMUSE JobServer launching"

      self.add_hosts(hosts=hosts,channel_type=channel_type)
Ejemplo n.º 3
0
    def test25(self):
        """ more test of pool: calls of same code """
        from amuse.rfi.async_request import AsyncRequestsPool
        instance1 = ForTesting(self.exefile)

        r1 = instance1.do_sleep(1, return_request=True)
        r2 = instance1.echo_int(2, return_request=True)

        p1 = AsyncRequestsPool()
        r1.wait()
        r2.wait()
        p1.add_request(r1)
        p1.add_request(r2)

        #~ p1=r1.join(r2)

        p1.waitall()

        self.assertEqual(r2.result(), 2)

        instance1.stop()
Ejemplo n.º 4
0
    def test23(self):

        pool = AsyncRequestsPool()

        x = ForTestingInterface(channel_type='sockets')
        y = ForTestingInterface(channel_type='sockets')
        request1 = x.sleep.asynchronous(0.2)
        request2 = y.sleep.asynchronous(0.2)
        finished_requests = []

        def handle_result(request, index):
            self.assertTrue(request.is_result_available())
            finished_requests.append(index)

        pool.add_request(request1, handle_result, [1])
        pool.add_request(request2, handle_result, [2])

        time.sleep(1.0)

        pool.wait()
        pool.wait()

        self.assertEquals(len(finished_requests), 2)
        self.assertEquals(len(pool), 0)

        self.assertTrue(request1.is_result_available())
        self.assertTrue(request2.is_result_available())

        self.assertEquals(request1.result(), 0)
        self.assertEquals(request2.result(), 0)

        pool.wait()
        self.assertEquals(len(pool), 0)

        y.stop()
        x.stop()
Ejemplo n.º 5
0
           channel_type='sockets',
           number_of_workers=1,
           case='bomex')

# explicitly initialize the codes
# otherwise implicitly done when calling evolve_model
d1.commit_parameters()
d2.commit_parameters()

# add parameter redirection='none' to see DALES diagnostics output

target_time = 120 | units.s  # target time

# create a pool for managing asynchronous requests
t = time.time()
pool = AsyncRequestsPool()

# add requests to the two codes to the pool
request1 = d1.evolve_model.asynchronous(target_time, exactEnd=True)
pool.add_request(request1)

request2 = d2.evolve_model.asynchronous(target_time, exactEnd=True)
pool.add_request(request2)

print('Generating asynchronous requests  %f s' % (time.time() - t))

# wait for the requests to finish
print('Calling pool.waitall()')
t = time.time()
pool.waitall()
print('pool.waitall() returned %f s' % (time.time() - t))