How to use the poap.mpiserve.MPIWorker function in POAP

To help you get started, we’ve selected a few POAP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbindel / POAP / poap / mpiserve.py View on Github external
super(MPISimpleWorker, self).__init__()
        self.f = f

    def eval(self, record_id, params):
        """Evaluate a function at a point.

        Args:
            record_id: Identifier for the function evaluation
            params: Set of parameters
        """
        logger.debug("Eval %d at %s", record_id, params)
        value = self.f(*params)
        self.finish_success(record_id, value)


class MPIProcessWorker(MPIWorker):
    """MPI worker that runs an evaluation in a subprocess

    The MPIProcessWorker is a base class for simulations that run a
    simulation in an external subprocess.  This class provides functionality
    just to allow graceful termination of the external simulations.

    Attributes:
        process: Handle for external subprocess
    """

    def __init__(self):
        super(MPIProcessWorker, self).__init__()
        self.process = None

    def kill_process(self):
        "Kill the child process"
github dbindel / POAP / poap / mpiserve.py View on Github external
logger.debug("Join worker eval thread")
                self._eval_thread.join()
                self._eval_thread = None
                logger.debug("Joined eval thread")
            else:
                try:
                    timeout = 0.005
                    msg = self._outbox.get(True, timeout)
                    logger.debug("MPI send to 0: %s", msg)
                    comm.send(msg, dest=0, tag=0)
                    logger.debug("MPI send completed")
                except Queue.Empty:
                    pass


class MPISimpleWorker(MPIWorker):
    """Worker that calls a Python function.

    The MPISimpleWorker does ordinary Python function evaluations.
    Requests to kill a running evaluation are simply ignored.
    """

    def __init__(self, f):
        super(MPISimpleWorker, self).__init__()
        self.f = f

    def eval(self, record_id, params):
        """Evaluate a function at a point.

        Args:
            record_id: Identifier for the function evaluation
            params: Set of parameters