Exemplo n.º 1
0
    def run(self):
        """Receiving job instructions from the master node until
        TERMINATE signal received. Allowed tasks are defined in taskDict
        """
        atimer = Timer('Worker')

        # tasks define signal-behavior in the run function
        taskDict = { MAP_START: self.map, REDUCE_START: self.reduce,\
                INIT_START: self.map,\
                UPDATE_MAP: self.update, UPDATE_REDUCE: self.update,\
                UPDATE_CONFIG: self.update }

        status = MPI.Status()
        while True:
            # ping input
            if not world.Iprobe(source=0, tag=MPI.ANY_TAG, status=status):
                sleep(self.config['delay'])

            # entire calculation finished
            elif status.tag == TERMINATE:
                term = world.recv(source=0, tag=TERMINATE)
                break

            # check allowed tasks
            elif status.tag in taskDict:
                taskDict[status.tag](status.tag)

            # no instruction found, looping
            else:
                sleep(self.config['delay'])
Exemplo n.º 2
0
    def wait(self, running, tag):
        """Test if any worker has finished its job.
        If so, decrease its key and make it available
        """
        atimer = Timer('Wait')

        inittime = time()
        status = MPI.Status()
        while time() - inittime < self.config['jobwait']:
            if world.Iprobe(source=MPI.ANY_SOURCE, tag=tag, status=status):
                jobf = world.recv(source=status.source, tag=tag)
                idx = 0
                for ii, worker in enumerate(self.workers):
                    if worker.id == status.source:
                        idx = ii
                        break
                if self.config['verbosity'] >= 8:
                    print('Freeing worker ' + str(self.workers[idx].id))
                worker = self.workers[idx]

                # faulty worker's job has already been cleaned
                if not worker.isFaulty():
                    del running[jobf]
                else:
                    self.nActive += 1
                worker.setFree()
                heapq._siftup(self.workers, idx)