示例#1
0
文件: mpi.py 项目: josegutab/scipion
def runJobMPISlave(mpiComm):
    """ This slave will be receiving commands to execute
    until 'None' is received. 
    """
    rank = mpiComm.Get_rank()
    print "Running runJobMPISlave: ", rank

    # Listen for commands until we get 'None'
    cwd = None  # We run without changing directory by default
    env = None  # And we don't change the environment either!
    
    while True:
        # Receive command in a non-blocking way
        req_recv = mpiComm.irecv(dest=0, tag=TAG_RUN_JOB+rank)
        while True:
            done, command = req_recv.test()
            if done:
                break
            sleep(1)

        print "Slave %d received command." % rank
        if command == 'None':
            print "  Stopping..."
            return

        # Run the command and get the result (exit code or exception)
        try:
            if command.startswith("cwd="):
                cwd = command.split("=", 1)[-1]
                print "  Changing to dir %s ..." % cwd
            elif command.startswith("env="):
                env = loads(command.split("=", 1)[-1])
                print "  Setting the environment..."
                if envVarOn('SCIPION_DEBUG'):
                    print env
            else:
                print "  %s" % command
                runCommand(command, cwd=cwd, env=env)
                cwd = None  # unset directory
                env = None  # unset environment
        except Exception as e:
            req_send = mpiComm.isend(str(e), dest=0, tag=TAG_RUN_JOB+rank)
            t0 = time()
            while not req_send.test()[0]:
                sleep(1)
                if time() - t0 > TIMEOUT:
                    print ("Timeout in process %d, cannot send error "
                           "message to master." % os.getpid())
                    return
            return

        # Send 0 (it worked!) in a non-blocking way.
        req_send = mpiComm.isend(0, dest=0, tag=TAG_RUN_JOB+rank)
        t0 = time()
        while not req_send.test()[0]:
            sleep(1)
            if time() - t0 > TIMEOUT:
                print ("Timeout in process %d, cannot send result "
                       "to master." % os.getpid())
                return
示例#2
0
文件: mpi.py 项目: totalcos/scipion
def runJobMPISlave(mpiComm):
    """ This slave will be receiving commands to execute
    until 'None' is received. 
    """
    rank = mpiComm.Get_rank()
    hostname = getLocalHostName()
    print "Running runJobMPISlave: ", rank

    exitResult = 0
    msg = "Timeout in process %d, cannot send result to master."

    # Listen for commands until we get 'None'
    cwd = None  # We run without changing directory by default
    env = None  # And we don't change the environment either!

    while True:
        # Receive command in a non-blocking way
        req_recv = mpiComm.irecv(dest=0, tag=TAG_RUN_JOB + rank)
        while True:
            done, command = req_recv.test()
            if done:
                break
            sleep(1)

        print "Slave %s(rank %d) received command." % (hostname, rank)
        if command == 'None':
            print "  Stopping..."
            return

        # Run the command and get the result (exit code or exception)
        try:
            if command.startswith("cwd="):
                cwd = command.split("=", 1)[-1]
                print "  Changing to dir %s ..." % cwd
            elif command.startswith("env="):
                env = loads(command.split("=", 1)[-1])
                print "  Setting the environment..."
                if envVarOn('SCIPION_DEBUG'):
                    print env
            else:
                print "  %s" % command
                runCommand(command, cwd=cwd, env=env)
                cwd = None  # unset directory
                env = None  # unset environment
        except Exception as e:

            msg = "Timeout in process %d, cannot send error message to master."
            exitResult = str(e)

        # Communicate to master, either error os success
        req_send = mpiComm.isend(exitResult, dest=0, tag=TAG_RUN_JOB + rank)
        t0 = time()
        while not req_send.test()[0]:
            sleep(1)
            if time() - t0 > TIMEOUT:
                print(msg % os.getpid())
                break
示例#3
0
 def getDataSet(cls, name):
     """
     This method is called every time the dataset want to be retreived
     """
     assert name in cls._datasetDict, "Dataset: %s dataset doesn't exist." % name
     folder = cls._datasetDict[name].folder
     if not envVarOn("SCIPION_TEST_NOSYNC"):
         scipion = "%s %s/scipion" % (os.environ["SCIPION_PYTHON"], os.environ["SCIPION_HOME"])
         command = scipion + " testdata --download " + folder
         print ">>>> " + command
         os.system(command)
     return cls._datasetDict[name]
示例#4
0
 def getDataSet(cls, name):
     """
     This method is called every time the dataset want to be retreived
     """
     assert name in cls._datasetDict, "Dataset: %s dataset doesn't exist." % name
     folder = cls._datasetDict[name].folder
     if not envVarOn('SCIPION_TEST_NOSYNC'):
         scipion = "%s %s/scipion" % (os.environ['SCIPION_PYTHON'],
                                      os.environ['SCIPION_HOME'])
         command = scipion + " testdata --download " + folder
         print ">>>> " + command
         os.system(command)
     return cls._datasetDict[name]
示例#5
0
 def newProtocol(cls, protocolClass, **kwargs):
     """ Create new protocols instances through the project
     and return a newly created protocol of the given class
     """
     # Try to continue from previous execution
     if envVarOn('SCIPION_TEST_CONTINUE'):
         candidates = cls.proj.mapper.selectByClass(protocolClass.__name__)
         if candidates:
             c = candidates[0]
             if c.isFinished():
                 setattr(c, '_run', False)
             else:
                 c.runMode.set(MODE_RESTART)
             return c
     return cls.proj.newProtocol(protocolClass, **kwargs)
示例#6
0
 def newProtocol(cls, protocolClass, **kwargs):
     """ Create new protocols instances through the project
     and return a newly created protocol of the given class
     """
     # Try to continue from previous execution
     if envVarOn("SCIPION_TEST_CONTINUE"):
         candidates = cls.proj.mapper.selectByClass(protocolClass.__name__)
         if candidates:
             c = candidates[0]
             if c.isFinished():
                 setattr(c, "_run", False)
             else:
                 c.runMode.set(MODE_RESTART)
             return c
     return cls.proj.newProtocol(protocolClass, **kwargs)