Exemplo n.º 1
0
def RunMasterSlave(masterClass, slaveClass, workParams, useMPI=True, finalRun=True):
    """
    This is a generic master/slave runner.
    """
    if HAVE_MPI and useMPI:
        MSRunner = SimpleMasterSlave(masterClass, slaveClass, workParams)
        balancer = PyparBalancer(MSRunner, False)
        balancer.run(finalRun)
        if MY_RANK==0:
            return MSRunner.getMasterInstance()
    else:
        #
        # run serially in case there's no MPI or the called doesn't want it.
        #
        master = masterClass()
        slave = slaveClass()
        for i in range(len(workParams)):
            master(i,slave(workParams[i]))

        return master
Exemplo n.º 2
0
def RunMasterSlave(masterClass, slaveClass, workParams, useMPI=True, finalRun=True):
    """
    This is a generic master/slave runner.
    """
    if HAVE_MPI and useMPI:
        MSRunner = SimpleMasterSlave(masterClass, slaveClass, workParams)
        balancer = PyparBalancer(MSRunner, False)
        balancer.run(finalRun)
        if MY_RANK==0:
            return MSRunner.getMasterInstance()
    else:
        #
        # run serially in case there's no MPI or the called doesn't want it.
        #
        master = masterClass()
        slave = slaveClass()
        for i in range(len(workParams)):
            master(i,slave(workParams[i]))

        return master
Exemplo n.º 3
0
def foreach(f, l, useMPI=True, return_=True, debug=False, finalRun=True):
    """
    for each element in list 'l' apply the function 'f'.
    You can force serial operation by setting useMPI to 'False'
    The last time you're call foreach... make sure finalRun=True.
    """
    if HAVE_MPI and useMPI:
        if debug and MY_RANK == 0:
            print "Found MPI environment with multiple nodes.. using MPI!"
        GMPI = GenericMPI(f, l, debug=debug)
        balancer = PyparBalancer(
            GMPI, False)  # set this to True to get lots of debugging output
        balancer.run(finalRun)
        if return_:
            if MY_RANK == 0:
                return GMPI.results
            else:
                return "You don't get results in this rank!:" + ` MY_RANK `
    else:
        #
        # just run serially
        #
        if debug:
            print "No MPI environment with multiple nodes.. evaluating serially."

        if return_:
            results = []
            for v in l:
                result = f(v)
                if debug:
                    print "Work item completed:", len(results), ':', result
                results.append(result)
            return results
        else:
            for v in l:
                f(v)
            return
Exemplo n.º 4
0
def foreach(f, l, useMPI=True, return_=True, debug=False, finalRun=True):
    """
    for each element in list 'l' apply the function 'f'.
    You can force serial operation by setting useMPI to 'False'
    The last time you're call foreach... make sure finalRun=True.
    """
    if HAVE_MPI and useMPI:
        if debug and MY_RANK==0:
            print "Found MPI environment with multiple nodes.. using MPI!"
        GMPI = GenericMPI(f, l, debug=debug)
        balancer = PyparBalancer(GMPI, False) # set this to True to get lots of debugging output
        balancer.run(finalRun)
        if return_:
            if MY_RANK==0:
                return GMPI.results
            else:
                return "You don't get results in this rank!:" + `MY_RANK`
    else:
        #
        # just run serially
        #
        if debug:
            print "No MPI environment with multiple nodes.. evaluating serially."

        if return_:
            results=[]
            for v in l:
                result = f(v)
                if debug:
                    print "Work item completed:", len(results), ':', result
                results.append(result)
            return results
        else:
            for v in l:
                f(v)
            return