Exemplo n.º 1
0
def main(argv):
    try:
        inputfile = "../finished.queue"
        xmlFile = "../../data/param_config_pressure.xml"

        try:
            opts, args = getopt.getopt(sys.argv[1:], "hi:x:v:", ["help", "ifile", "xfile", "verbose"])
        except getopt.GetoptError, err:
            print str(err)
            return
        for o, val in opts:
            if o in ("-i", "--ifile"):
                inputfile = val
            elif o in ("-x", "--xfile"):
                xmlFile = val
            else:
                assert False, "unhandled option"

        solutionBase = SolutionFusion(xmlFile)

        init()
        i = 0
        f = open(inputfile, 'r')
        if not os.path.exists("bootstrap"):
            os.makedirs("bootstrap")
        savedPath = os.getcwd()

        create_script_file()

        for line in f.readlines():
            solTuple = line.split('#')
            solValue = float(solTuple[1])
            if (solValue < 0.0):
                continue
            util.logger.info("Processing solution " + str(i+1) + " with value " + str(solValue))
            create_bootstrap_folder(i)
            sol = solTuple[0]
            parameters = sol.split(',')
            params = []
            for p in parameters:
                params.append(float(p.split(':')[1]))
            solutionBase.setParametersValues(params)
            solutionBase.getData().create_input_file("bootstrap/" + str(i) + "/input.tj0")
            os.chdir(savedPath+"/bootstrap/"+str(i))
            commands.getoutput("ln -s " + savedPath + "/remote_bootstrap.py remote_bootstrap.py")
            commands.getoutput("ln -s " + savedPath + "/send_bootstrap send_bootstrap")

            util.logger.info("Submitting job")
            commands.getoutput("qsub send_bootstrap")
            os.chdir(savedPath)
            i += 1
        f.close()
Exemplo n.º 2
0
    def run(self, infile, cfile):
        try:
            startTime = time()
            config = ConfigParser.ConfigParser()
            config.read(cfile)
            if (config.has_option("Algorithm", "time")):
                val = config.get("Algorithm", "time")
                if (val != None):
                    self.__runtime = int(val)
            if (config.has_option("Algorithm", "objective")):
                val = config.get("Algorithm", "objective")
                if (val != None):
                    if (val == "max"):
                        u.objective = u.objectiveType.MAXIMIZE
                    else:
                        u.objective = u.objectiveType.MINIMIZE
            elapsedTime = time() - startTime
            solutionsEvaluated = 0
            """
            Send the finish message 10 minutes before the end time to allow
            the jobs that are still running to finish on time
            """
            while((elapsedTime + (60 * 5)) < self.__runtime):
                #solution = SolutionFusion()
                #Send a request for data
                status = MPI.Status()
                if (self.__problemType == u.problemType.FUSION):
                    solution = SolutionFusion(infile)
                elif (self.__problemType == u.problemType.NONSEPARABLE):
                    solution = SolutionNonSeparable(infile)
                numParams = solution.getNumberofParams()
                buff = array('f', [0]) * numParams
                solValue = array('f', [0]) * 1
                dump = array('i', [0]) * 1
                u.logger.debug("SLAVE (" + str(self.__rank) +
                               ") waiting for a solution")
                #self.__comm.Isend(dump, dest=0, tag=u.tags.REQINPUT)
                self.__comm.Send(dump, dest=0, tag=u.tags.REQINPUT)

                agentIdx = array('i', [0]) * 1
                #Receive the solution
                req = self.__comm.Irecv(buff, 0, u.tags.RECVFROMMASTER)
                req.wait(status)

                #Receive the bee id
                req = self.__comm.Irecv(agentIdx, 0, u.tags.RECVFROMMASTER)
                req.wait(status)

                u.logger.info("SLAVE (" + str(self.__rank) +
                               ") has received a solution from bee " +
                               str(agentIdx[0]))
                solution.setParametersValues(buff)

                #Evalute the solution
                self.__problem.solve(solution)

                buff = solution.getParametersValues()
                solValue[0] = float(solution.getValue())

                #Send the solution back together with the bee id
                req = self.__comm.Isend([dump, MPI.INT], 0,
                                        u.tags.REQSENDINPUT)
                req.Wait(status)

                u.logger.debug("SLAVE (" + str(self.__rank) +
                               "). Buffer size: " + str(len(buff)))

                self.__comm.Send(buff, 0, u.tags.COMMSOLUTION)
                self.__comm.Send(solValue, 0, u.tags.COMMSOLUTION)
                self.__comm.Send(agentIdx, 0, u.tags.COMMSOLUTION)

                elapsedTime = time() - startTime
                solutionsEvaluated += 1
                u.logger.debug("SLAVE (" + str(self.__rank) + ") elapsed " +
                                str(elapsedTime) + " - Runtime " +
                                str(self.__runtime))
            u.logger.info("SLAVE (" + str(self.__rank) +
                          ") configurations evaluated: " +
                           str(solutionsEvaluated))
        except Exception, e:
            u.logger.error("SLAVE (" + str(self.__rank) + ")" +
                           str(sys.exc_traceback.tb_lineno) + " " + str(e))