Пример #1
0
    def buildMPIrun(self, argv, expandApplication=True):
        """Builds a list with a working mpirun command (for that MPI-Implementation)
        @param argv: the original arguments that are to be wrapped
        @param expandApplication: Expand the
        @return: list with the correct mpirun-command"""

        mpirun = ["mpprun"]

        progname = argv[0]
        if expandApplication:
            stat, progname = commands.getstatusoutput('which '+progname)
            if stat:
                progname = argv[0]
                warning(
                    "which can not find a match for",
                    progname, ". Hoping for the best"
                )

        mpirun += [progname] + argv[1:3] + ["-parallel"] + argv[3:]

        if config().getdebug("ParallelExecution"):
            debug("MPI:", foamMPI())
            debug("Arguments:", mpirun)
            system("which mpirun")
            system("which rsh")
            debug("Environment", environ)
            for a in mpirun:
                if a in environ:
                    debug("Transfering variable", a, "with value", environ[a])

        return mpirun
Пример #2
0
    def buildMPIrun(self, argv, expandApplication=True):
        """Builds a list with a working mpirun command (for that MPI-Implementation)
        @param argv: the original arguments that are to be wrapped
        @param expandApplication: Expand the
        @return: list with the correct mpirun-command"""

        nr = str(self.cpuNr())
        mpirun = [config().get("MPI", "run_" + foamMPI(), default="mpirun")]
        mpiRunPath = self.which(" ".join(mpirun))
        if not mpiRunPath:
            error("Could not find a path for", mpirun,
                  "Check configuration variable", "run_" + foamMPI(),
                  "in section 'MPI'")
        mpirun += eval(config().get("MPI",
                                    "options_" + foamMPI() + "_pre",
                                    default="[]"))

        if (foamMPI() == "LAM"):
            mpirun += ["-np", nr]
        elif foamMPI().find("OPENMPI") >= 0:
            nr = []
            if "MPI_ARCH_PATH" in environ and config().getboolean(
                    "MPI", "OpenMPI_add_prefix"):
                nr += ["--prefix", environ["MPI_ARCH_PATH"]]
            if self.procNr != None:
                nr += ["--n", str(self.procNr)]
            machine = []
            if self.mFile != None:
                machine = ["--machinefile", self.mFile]
                if config().getdebug("ParallelExecution"):
                    debug("Start of", self.mFile)
                    debug("\n" + open(self.mFile).read())
                    debug("End of", self.mFile)
            mpirun += machine + nr
        else:
            error(" Unknown or missing MPI-Implementation for mpirun: " +
                  foamMPI())

        mpirun += eval(config().get("MPI",
                                    "options_" + foamMPI() + "_post",
                                    default="[]"))

        progname = argv[0]
        if expandApplication:
            # old implementation: stat,progname=commands.getstatusoutput('which '+progname)
            progname = self.which(progname)
            if progname:
                progname = argv[0]
                warning("which can not find a match for", progname,
                        ". Hoping for the best")

        if oldAppConvention():
            mpirun += [progname] + argv[1:3] + ["-parallel"] + argv[3:]
        else:
            mpirun += [progname] + argv[1:] + ["-parallel"]

        if config().getdebug("ParallelExecution"):
            debug("MPI:", foamMPI())
            debug("Arguments:", mpirun)
            system("which mpirun")
            system("which rsh")
            debug("Environment", environ)
            for a in mpirun:
                if a in environ:
                    debug("Transfering variable", a, "with value", environ[a])

        return mpirun
Пример #3
0
    def __init__(self,
                 argv=None,
                 silent=False,
                 logname=None,
                 compressLog=False,
                 lam=None,
                 server=False,
                 restart=False,
                 noLog=False,
                 logTail=None,
                 remark=None,
                 jobId=None,
                 parameters=None,
                 writeState=True,
                 echoCommandLine=None):
        """:param argv: list with the tokens that are the command line
        if not set the standard command line is used
        :param silent: if True no output is sent to stdout
        :param logname: name of the logfile
        :param compressLog: Compress the logfile into a gzip
        :param lam: Information about a parallel run
        :param server: Whether or not to start the network-server
        :type lam: PyFoam.Execution.ParallelExecution.LAMMachine
        :param noLog: Don't output a log file
        :param logTail: only the last lines of the log should be written
        :param remark: User defined remark about the job
        :param parameters: User defined dictionary with parameters for
                 documentation purposes
        :param jobId: Job ID of the controlling system (Queueing system)
        :param writeState: Write the state to some files in the case
        :param echoCommandLine: Prefix that is printed with the command line. If unset nothing is printed
        """

        if sys.version_info < (2, 3):
            # Python 2.2 does not have the capabilities for the Server-Thread
            if server:
                warning(
                    "Can not start server-process because Python-Version is too old"
                )
            server = False

        if argv == None:
            self.argv = sys.argv[1:]
        else:
            self.argv = argv

        if oldApp():
            self.dir = path.join(self.argv[1], self.argv[2])
            if self.argv[2][-1] == path.sep:
                self.argv[2] = self.argv[2][:-1]
        else:
            self.dir = path.curdir
            if "-case" in self.argv:
                self.dir = self.argv[self.argv.index("-case") + 1]

        logname = calcLogname(logname, argv)

        try:
            sol = self.getSolutionDirectory()
        except OSError:
            e = sys.exc_info()[1]  # compatible with 2.x and 3.x
            error("Solution directory", self.dir,
                  "does not exist. No use running. Problem:", e)

        self.echoCommandLine = echoCommandLine
        self.silent = silent
        self.lam = lam
        self.origArgv = self.argv
        self.writeState = writeState
        self.__lastLastSeenWrite = 0
        self.__lastNowTimeWrite = 0

        if self.lam != None:
            self.argv = lam.buildMPIrun(self.argv)
            if config().getdebug("ParallelExecution"):
                debug("Command line:", " ".join(self.argv))
        self.cmd = " ".join(self.argv)
        foamLogger().info("Starting: " + self.cmd + " in " +
                          path.abspath(path.curdir))
        self.logFile = path.join(self.dir, logname + ".logfile")

        isRestart, restartnr, restartName, lastlog = findRestartFiles(
            self.logFile, sol)

        if restartName:
            self.logFile = restartName

        if not isRestart:
            from os import unlink
            from glob import glob
            for g in glob(self.logFile + ".restart*"):
                if path.isdir(g):
                    rmtree(g)
                else:
                    unlink(g)

        self.noLog = noLog
        self.logTail = logTail
        if self.logTail:
            if self.noLog:
                warning("Log tail", self.logTail,
                        "and no-log specified. Using logTail")
            self.noLog = True
            self.lastLines = []

        self.compressLog = compressLog
        if self.compressLog:
            self.logFile += ".gz"

        self.fatalError = False
        self.fatalFPE = False
        self.fatalStackdump = False
        self.endSeen = False
        self.warnings = 0
        self.started = False

        self.isRestarted = False
        if restart:
            self.controlDict = ParameterFile(path.join(self.dir, "system",
                                                       "controlDict"),
                                             backup=True)
            self.controlDict.replaceParameter("startFrom", "latestTime")
            self.isRestarted = True
        else:
            self.controlDict = None

        self.run = FoamThread(self.cmd, self)

        self.server = None
        if server:
            self.server = FoamServer(run=self.run, master=self)
            self.server.setDaemon(True)
            self.server.start()
            try:
                IP, PID, Port = self.server.info()
                f = open(path.join(self.dir, "PyFoamServer.info"), "w")
                print_(IP, PID, Port, file=f)
                f.close()
            except AttributeError:
                warning(
                    "There seems to be a problem with starting the server:",
                    self.server, "with attributes", dir(self.server))
                self.server = None

        self.createTime = None
        self.nowTime = None
        self.startTimestamp = time()

        self.stopMe = False
        self.writeRequested = False

        self.endTriggers = []

        self.lastLogLineSeen = None
        self.lastTimeStepSeen = None

        self.remark = remark
        self.jobId = jobId

        self.data = {"lines": 0}  #        self.data={"lines":0L}
        self.data["logfile"] = self.logFile
        self.data["casefullname"] = path.abspath(self.dir)
        self.data["casename"] = path.basename(path.abspath(self.dir))
        self.data["solver"] = path.basename(self.argv[0])
        self.data["solverFull"] = self.argv[0]
        self.data["commandLine"] = self.cmd
        self.data["hostname"] = uname()[1]
        if remark:
            self.data["remark"] = remark
        else:
            self.data["remark"] = "No remark given"
        if jobId:
            self.data["jobId"] = jobId
        parameterFile = sol.getParametersFromFile()
        if len(parameterFile):
            self.data["parameters"] = {}
            for k, v in parameterFile.items():
                self.data["parameters"][k] = makePrimitiveString(v)
        if parameters:
            if "parameters" not in self.data:
                self.data["parameters"] = {}
            self.data["parameters"].update(parameters)
        self.data["starttime"] = asctime()
Пример #4
0
    def __init__(self,
                 argv=None,
                 silent=False,
                 logname=None,
                 compressLog=False,
                 lam=None,
                 server=False,
                 restart=False,
                 noLog=False,
                 logTail=None,
                 remark=None,
                 jobId=None,
                 parameters=None,
                 writeState=True,
                 echoCommandLine=None):
        """@param argv: list with the tokens that are the command line
        if not set the standard command line is used
        @param silent: if True no output is sent to stdout
        @param logname: name of the logfile
        @param compressLog: Compress the logfile into a gzip
        @param lam: Information about a parallel run
        @param server: Whether or not to start the network-server
        @type lam: PyFoam.Execution.ParallelExecution.LAMMachine
        @param noLog: Don't output a log file
        @param logTail: only the last lines of the log should be written
        @param remark: User defined remark about the job
        @param parameters: User defined dictionary with parameters for
                 documentation purposes
        @param jobId: Job ID of the controlling system (Queueing system)
        @param writeState: Write the state to some files in the case
        @param echoCommandLine: Prefix that is printed with the command line. If unset nothing is printed
        """

        if sys.version_info < (2,3):
            # Python 2.2 does not have the capabilities for the Server-Thread
            if server:
                warning("Can not start server-process because Python-Version is too old")
            server=False

        if argv==None:
            self.argv=sys.argv[1:]
        else:
            self.argv=argv

        if oldApp():
            self.dir=path.join(self.argv[1],self.argv[2])
            if self.argv[2][-1]==path.sep:
                self.argv[2]=self.argv[2][:-1]
        else:
            self.dir=path.curdir
            if "-case" in self.argv:
                self.dir=self.argv[self.argv.index("-case")+1]

        if logname==None:
            logname="PyFoam."+path.basename(argv[0])

        try:
            sol=self.getSolutionDirectory()
        except OSError:
            e = sys.exc_info()[1] # compatible with 2.x and 3.x
            error("Solution directory",self.dir,"does not exist. No use running. Problem:",e)

        self.echoCommandLine=echoCommandLine
        self.silent=silent
        self.lam=lam
        self.origArgv=self.argv
        self.writeState=writeState
        self.__lastLastSeenWrite=0
        self.__lastNowTimeWrite=0

        if self.lam!=None:
            self.argv=lam.buildMPIrun(self.argv)
            if config().getdebug("ParallelExecution"):
                debug("Command line:"," ".join(self.argv))
        self.cmd=" ".join(self.argv)
        foamLogger().info("Starting: "+self.cmd+" in "+path.abspath(path.curdir))
        self.logFile=path.join(self.dir,logname+".logfile")

        self.noLog=noLog
        self.logTail=logTail
        if self.logTail:
            if self.noLog:
                warning("Log tail",self.logTail,"and no-log specified. Using logTail")
            self.noLog=True
            self.lastLines=[]

        self.compressLog=compressLog
        if self.compressLog:
            self.logFile+=".gz"

        self.fatalError=False
        self.fatalFPE=False
        self.fatalStackdump=False

        self.warnings=0
        self.started=False

        self.isRestarted=False
        if restart:
            self.controlDict=ParameterFile(path.join(self.dir,"system","controlDict"),backup=True)
            self.controlDict.replaceParameter("startFrom","latestTime")
            self.isRestarted=True
        else:
            self.controlDict=None

        self.run=FoamThread(self.cmd,self)

        self.server=None
        if server:
            self.server=FoamServer(run=self.run,master=self)
            self.server.setDaemon(True)
            self.server.start()
            try:
                IP,PID,Port=self.server.info()
                f=open(path.join(self.dir,"PyFoamServer.info"),"w")
                print_(IP,PID,Port,file=f)
                f.close()
            except AttributeError:
                warning("There seems to be a problem with starting the server:",self.server,"with attributes",dir(self.server))
                self.server=None

        self.createTime=None
        self.nowTime=None
        self.startTimestamp=time()

        self.stopMe=False
        self.writeRequested=False

        self.endTriggers=[]

        self.lastLogLineSeen=None
        self.lastTimeStepSeen=None

        self.remark=remark
        self.jobId=jobId

        self.data={"lines":0} #        self.data={"lines":0L}
        self.data["logfile"]=self.logFile
        self.data["casefullname"]=path.abspath(self.dir)
        self.data["casename"]=path.basename(path.abspath(self.dir))
        self.data["solver"]=path.basename(self.argv[0])
        self.data["solverFull"]=self.argv[0]
        self.data["commandLine"]=self.cmd
        self.data["hostname"]=uname()[1]
        if remark:
            self.data["remark"]=remark
        else:
            self.data["remark"]="No remark given"
        if jobId:
            self.data["jobId"]=jobId
        parameterFile=sol.getParametersFromFile()
        if len(parameterFile):
            self.data["parameters"]={}
            for k,v in parameterFile.items():
                self.data["parameters"][k]=makePrimitiveString(v)
        if parameters:
            if "parameters" not in self.data:
                self.data["parameters"]={}
            self.data["parameters"].update(parameters)
        self.data["starttime"]=asctime()
Пример #5
0
    def buildMPIrun(self,argv,expandApplication=True):
        """Builds a list with a working mpirun command (for that MPI-Implementation)
        @param argv: the original arguments that are to be wrapped
        @param expandApplication: Expand the
        @return: list with the correct mpirun-command"""

        nr=str(self.cpuNr())
        mpirun=[config().get("MPI","run_"+foamMPI(),default="mpirun")]
        mpiRunPath=self.which(" ".join(mpirun))
        if not mpiRunPath:
            error("Could not find a path for",mpirun,
                  "Check configuration variable","run_"+foamMPI(),
                  "in section 'MPI'")
        mpirun+=eval(config().get("MPI","options_"+foamMPI()+"_pre",default="[]"))

        if(foamMPI()=="LAM"):
            mpirun+=["-np",nr]
        elif foamMPI().find("OPENMPI")>=0:
            nr=[]
            if "MPI_ARCH_PATH" in environ and config().getboolean("MPI","OpenMPI_add_prefix"):
                nr+=["--prefix",environ["MPI_ARCH_PATH"]]
            if self.procNr!=None:
                nr+=["--n",str(self.procNr)]
            machine=[]
            if self.mFile!=None:
                machine=["--machinefile",self.mFile]
                if config().getdebug("ParallelExecution"):
                    debug("Start of",self.mFile)
                    debug("\n"+open(self.mFile).read())
                    debug("End of",self.mFile)
            mpirun+=machine+nr
        else:
            error(" Unknown or missing MPI-Implementation for mpirun: "+foamMPI())

        mpirun+=eval(config().get("MPI","options_"+foamMPI()+"_post",default="[]"))

        progname=argv[0]
        if expandApplication:
            # old implementation: stat,progname=commands.getstatusoutput('which '+progname)
            progname=self.which(progname)
            if progname:
                progname=argv[0]
                warning("which can not find a match for",progname,". Hoping for the best")

        if oldAppConvention():
            mpirun+=[progname]+argv[1:3]+["-parallel"]+argv[3:]
        else:
            mpirun+=[progname]+argv[1:]+["-parallel"]

        if config().getdebug("ParallelExecution"):
            debug("MPI:",foamMPI())
            debug("Arguments:",mpirun)
            system("which mpirun")
            system("which rsh")
            debug("Environment",environ)
            for a in mpirun:
                if a in environ:
                    debug("Transfering variable",a,"with value",environ[a])

        return mpirun