def parse(self, nr=None, exactNr=True): """ parse the options @param nr: minimum number of arguments that are to be passed to the application 3 is default for pre-1.5 versions of OpenFOAM """ (self.options, self.args) = self.parse_args(args=self.argLine) if "foamVersion" in dir(self.options): if self.options.foamVersion != None: if self.options.force32 and self.options.force64: error("A version can't be 32 and 64 bit at the same time") self.__foamVersionChanged = True self.__oldEnvironment = deepcopy(environ) changeFoamVersion(self.options.foamVersion, force64=self.options.force64, force32=self.options.force32, compileOption=self.options.compileOption, foamCompiler=self.options.foamCompiler, wmCompiler=self.options.wmCompiler) elif self.options.force32 or self.options.force64: warning( "Forcing version to be 32 or 64 bit, but no version chosen. Doing nothing" ) elif self.options.compileOption: warning( "No OpenFOAM-version chosen. Can't set compile-option to", self.options.compileOption) if nr == None: if oldApp(): nr = 3 else: nr = 1 if len(self.args) < nr: self.error("Too few arguments (%d needed, %d given)" % (nr, len(self.args))) maxNr = nr if not oldApp(): if "-case" in self.args: maxNr += 2 if exactNr and len(self.args) > maxNr: self.error("Too many arguments (%d needed, %d given)" % (nr, len(self.args))) tmp = self.args self.args = [] for a in tmp: if a.find(" ") >= 0 or a.find("(") >= 0: a = "\"" + a + "\"" self.args.append(a)
def parse(self,nr=None,exactNr=True): """ parse the options :param nr: minimum number of arguments that are to be passed to the application 3 is default for pre-1.5 versions of OpenFOAM """ (self.options,self.args)=self.parse_args(args=self.argLine) if "foamVersion" in dir(self.options): if self.options.foamVersion!=None: if self.options.force32 and self.options.force64: error("A version can't be 32 and 64 bit at the same time") self.__foamVersionChanged=True self.__oldEnvironment=deepcopy(environ) changeFoamVersion(self.options.foamVersion, force64=self.options.force64, force32=self.options.force32, compileOption=self.options.compileOption, foamCompiler=self.options.foamCompiler, wmCompiler=self.options.wmCompiler) elif self.options.force32 or self.options.force64: warning("Forcing version to be 32 or 64 bit, but no version chosen. Doing nothing") elif self.options.compileOption: warning("No OpenFOAM-version chosen. Can't set compile-option to",self.options.compileOption) if nr==None: if oldApp(): nr=3 else: nr=1 if len(self.args)<nr: self.error("Too few arguments (%d needed, %d given)" %(nr,len(self.args))) maxNr=nr if not oldApp(): if "-case" in self.args: maxNr+=2 if exactNr and len(self.args)>maxNr: self.error("Too many arguments (%d needed, %d given)" %(nr,len(self.args))) tmp=self.args self.args=[] for a in tmp: if a.find(" ")>=0 or a.find("(")>=0: a="\""+a+"\"" self.args.append(a)
def setUp(self): self.theFile = mktemp() turb = path.join(simplePitzTutorial(), "constant") if oldApp(): turb = path.join(turb, "turbulenceProperties") else: turb = path.join(turb, "RASProperties") copyfile(turb, self.theFile)
def setUp(self): self.theFile="/tmp/test.turbulence" turb=path.join(simplePitzTutorial(),"constant") if oldApp(): turb=path.join(turb,"turbulenceProperties") else: turb=path.join(turb,"RASProperties") system("cp "+turb+" "+self.theFile)
def run(self): cName = self.parser.getArgs()[0] sol = SolutionDirectory(cName, archive=None) self.addLocalConfig(cName) initial = sol[0] if "U" not in initial or "p" not in initial: error("Either 'p' or 'U' missing from the initial directory", initial.baseName()) if self.opts.writep: initial["p.prepotential"] = initial["p"] initial["U.prepotential"] = initial["U"] lam = self.getParallel(sol) if self.opts.writep: writep = ["-writep"] else: writep = [] argv = ["potentialFoam"] if oldApp(): argv += [".", cName] else: argv += ["-case", cName] self.setLogname(default="Potential", useApplication=False) self.checkAndCommit(sol) run = BasicRunner(argv=argv + writep, server=self.opts.server, logname=self.opts.logname, compressLog=self.opts.compress, silent=self.opts.progress or self.opts.silent, lam=lam, logTail=self.opts.logTail, echoCommandLine=self.opts.echoCommandPrefix, noLog=self.opts.noLog) print_("Setting system-directory for potentialFoam") trig = PotentialTrigger(sol, self.opts.noCorr, self.opts.tolerance, self.opts.relTol, pRefCell=self.opts.pRefCell, pRefValue=self.opts.pRefValue, removeLibs=self.opts.removeLibs, removeFunctions=self.opts.removeFunctions) run.addEndTrigger(trig.resetIt) self.addToCaseLog(cName, "Starting") run.start() self.setData(run.data) self.addToCaseLog(cName, "Ending")
def setUp(self): self.theFile=mktemp() turb=path.join(simplePitzTutorial(),"constant") if oldApp(): turb=path.join(turb,"turbulenceProperties") else: turb=path.join(turb,"RASProperties") copyfile(turb,self.theFile)
def casePath(self): """Returns the path to the case (if applicable)""" if oldApp(): return path.join(self.getArgs()[1],self.getArgs()[2]) else: if "-case" in self.getArgs(): return path.normpath(self.getArgs()[self.getArgs().index("-case")+1]) else: return path.abspath(path.curdir)
def casePath(self): """Returns the path to the case (if applicable)""" if oldApp(): return path.join(self.getArgs()[1],self.getArgs()[2]) else: if "-case" in self.getArgs(): return path.normpath(self.getArgs()[self.getArgs().index("-case")+1]) else: return path.abspath(path.curdir)
def foamRun(self,application, args=[], foamArgs=[], steady=False, multiRegion=None, progress=False, noLog=False): """Runs a foam utility on the case. If it is a parallel job and the grid has already been decomposed (and not yet reconstructed) it is run in parallel @param application: the Foam-Application that is to be run @param foamArgs: A list if with the additional arguments for the Foam-Application @param args: A list with additional arguments for the Runner-object @param steady: Use the steady-runner @param multiRegion: Run this on multiple regions (if None: I don't have an opinion on this) @param progress: Only output the time and nothing else @param noLog: Do not generate a logfile""" arglist=args[:] arglist+=["--job-id=%s" % self.fullJobId()] if self.isDecomposed and self.nproc>1: arglist+=["--procnr=%d" % self.nproc, "--machinefile=%s" % self.hostfile] if progress: arglist+=["--progress"] if noLog: arglist+=["--no-log"] if self.multiRegion: if multiRegion==None or multiRegion==True: arglist+=["--all-regions"] elif multiRegion and not self.multiRegion: warning("This is not a multi-region case, so trying to run stuff multi-region won't do any good") if self.restarted: arglist+=["--restart"] arglist+=[application] if oldApp(): arglist+=[".",self.casename()] else: arglist+=["-case",self.casename()] arglist+=foamArgs self.message("Executing",arglist) if steady: self.message("Running Steady") runner=SteadyRunner(args=arglist) else: runner=Runner(args=arglist)
def run(self): cName=self.parser.getArgs()[0] sol=SolutionDirectory(cName,archive=None) # self.addLocalConfig(cName) initial=sol[0] if "U" not in initial or "p" not in initial: error("Either 'p' or 'U' missing from the initial directory",initial.baseName()) if self.opts.writep: initial["p.prepotential"]=initial["p"] initial["U.prepotential"]=initial["U"] lam=self.getParallel(sol) if self.opts.writep: writep=["-writep"] else: writep=[] argv=["potentialFoam"] if oldApp(): argv+=[".",cName] else: argv+=["-case",cName] self.setLogname(default="Potential",useApplication=False) self.checkAndCommit(sol) run=BasicRunner(argv=argv+writep, server=self.opts.server, logname=self.opts.logname, compressLog=self.opts.compress, silent=self.opts.progress or self.opts.silent, lam=lam, logTail=self.opts.logTail, echoCommandLine=self.opts.echoCommandPrefix, noLog=self.opts.noLog) print_("Setting system-directory for potentialFoam") trig=PotentialTrigger(sol, self.opts.noCorr, self.opts.tolerance, self.opts.relTol, pRefCell=self.opts.pRefCell, pRefValue=self.opts.pRefValue, removeLibs=self.opts.removeLibs, removeFunctions=self.opts.removeFunctions) run.addEndTrigger(trig.resetIt) self.addToCaseLog(cName,"Starting") run.start() self.setData(run.data) self.addToCaseLog(cName,"Ending")
def testBoundaryRead(self): mesh = MeshInformation(self.dest) self.assertEqual(mesh.nrOfFaces(), 9176) self.assertEqual(mesh.nrOfPoints(), 4746) self.assertEqual(mesh.nrOfCells(), 2268) try: self.assertEqual(mesh.nrOfCells(), 2268) except: if not oldApp(): self.fail()
def testBoundaryRead(self): mesh=MeshInformation(self.dest) self.assertEqual(mesh.nrOfFaces(),9176) self.assertEqual(mesh.nrOfPoints(),4746) self.assertEqual(mesh.nrOfCells(),2268) try: self.assertEqual(mesh.nrOfCells(),2268) except: if not oldApp(): self.fail()
def setUp(self): self.dest="/tmp/TestDamBreak" SolutionDirectory(damBreakTutorial(),archive=None,paraviewLink=False).cloneCase(self.dest) if oldApp(): pathSpec=[path.dirname(self.dest),path.basename(self.dest)] else: pathSpec=["-case",self.dest] run=UtilityRunner(argv=["blockMesh"]+pathSpec,silent=True,server=False) run.start()
def buildRegionArgv(self,case,region): args=self.parser.getArgs()[:] if oldApp(): if region!=None: args[2]+="."+region else: if region!=None: if "-case" in args: args[args.index("-case")+1]=case+"."+region else: args+=["-case",case+"."+region] return args
def setUp(self): self.dest = mktemp() SolutionDirectory(damBreakTutorial(), archive=None, paraviewLink=False).cloneCase(self.dest) if oldApp(): pathSpec = [path.dirname(self.dest), path.basename(self.dest)] else: pathSpec = ["-case", self.dest] run = UtilityRunner(argv=["blockMesh"] + pathSpec, silent=False, server=False) run.start()
def __init__(self, args=None, usage=None, version=None, description=None, interspersed=False): """ @param usage: usage string. If missing a default is used @param version: if missing the PyFoam-version is used @param description: description of the utility @param interspersed: needs to be false if options should be passed to an OpenFOAM-utility @param args: Command line arguments. If unset sys.argv[1:] is used. Can be a string: it will be splitted then unsing the spaces (very primitive), or a list of strings (prefered) """ if usage == None: if oldApp(): usage = "%prog [options] <foamApplication> <caseDir> <caseName> [foamOptions]" else: usage = "%prog [options] <foamApplication> [foamOptions]" if version == None: version = "%prog " + versionString() if args == None: self.argLine = None elif type(args) == str: self.argLine = args.split() else: self.argLine = map(str, args) OptionParser.__init__( self, usage=usage, # prog=self.__type__.__name__, version=version, description=description, formatter=TitledHelpFormatter()) if interspersed: self.enable_interspersed_args() else: self.disable_interspersed_args() self.options = None self.args = None self.__foamVersionChanged = False self.__oldEnvironment = None
def __init__(self, args=None, usage=None, version=None, description=None, interspersed=False): """ @param usage: usage string. If missing a default is used @param version: if missing the PyFoam-version is used @param description: description of the utility @param interspersed: needs to be false if options should be passed to an OpenFOAM-utility @param args: Command line arguments. If unset sys.argv[1:] is used. Can be a string: it will be splitted then unsing the spaces (very primitive), or a list of strings (prefered) """ if usage==None: if oldApp(): usage="%prog [options] <foamApplication> <caseDir> <caseName> [foamOptions]" else: usage="%prog [options] <foamApplication> [foamOptions]" if version==None: version="%prog "+versionString() if args==None: self.argLine=None elif type(args)==str: self.argLine=args.split() else: self.argLine=map(str,args) OptionParser.__init__(self, usage=usage, # prog=self.__type__.__name__, version=version, description=description, formatter=TitledHelpFormatter()) if interspersed: self.enable_interspersed_args() else: self.disable_interspersed_args() self.options=None self.args=None self.__foamVersionChanged=False self.__oldEnvironment=None
class CommonMultiRegion(object): """ The class that looks for multiple mesh regions """ def addOptions(self): grp = OptionGroup(self.parser, "Multiple regions", "Treatment of cases with multiple mesh regions") grp.add_option( "--all-regions", action="store_true", default=False, dest="regions", help= "Executes the command for all available regions (builds a pseudo-case for each region)" ) grp.add_option( "--region", dest="region", action="append", default=None, help= "Executes the command for a region (builds a pseudo-case for that region). A value of 'region0' is the default region" ) grp.add_option( "--keep-pseudocases", action="store_true", default=False, dest="keeppseudo", help="Keep the pseudo-cases that were built for a multi-region case" ) self.parser.add_option_group(grp) def buildRegionArgv(self, case, region): args = self.parser.getArgs()[:] if oldApp(): if region != None: args[2] += "." + region else: if region != None: if "-case" in args: args[args.index("-case") + 1] = case + "." + region else: args += ["-case", case + "." + region] return args
def run(self): decomposeParWithRegion=(foamVersion()>=(1,6)) if self.opts.keeppseudo and (not self.opts.regions and self.opts.region==None): warning("Option --keep-pseudocases only makes sense for multi-region-cases") if decomposeParWithRegion and self.opts.keeppseudo: warning("Option --keep-pseudocases doesn't make sense since OpenFOAM 1.6 because decomposePar supports regions") nr=int(self.parser.getArgs()[1]) if nr<2: error("Number of processors",nr,"too small (at least 2)") case=path.abspath(self.parser.getArgs()[0]) method=self.opts.method result={} result["numberOfSubdomains"]=nr result["method"]=method coeff={} result[method+"Coeffs"]=coeff if self.opts.globalFaceZones!=None: try: fZones=eval(self.opts.globalFaceZones) except SyntaxError: fZones=FoamStringParser( self.opts.globalFaceZones, listDict=True ).data result["globalFaceZones"]=fZones if method in ["metis","scotch","parMetis"]: if self.opts.processorWeights!=None: weigh=eval(self.opts.processorWeights) if nr!=len(weigh): error("Number of processors",nr,"and length of",weigh,"differ") coeff["processorWeights"]=weigh elif method=="manual": if self.opts.dataFile==None: error("Missing required option dataFile") else: coeff["dataFile"]="\""+self.opts.dataFile+"\"" elif method=="simple" or method=="hierarchical": if self.opts.n==None or self.opts.delta==None: error("Missing required option n or delta") n=eval(self.opts.n) if len(n)!=3: error("Needs to be three elements, not",n) if nr!=n[0]*n[1]*n[2]: error("Subdomains",n,"inconsistent with processor number",nr) coeff["n"]="(%d %d %d)" % (n[0],n[1],n[2]) coeff["delta"]=float(self.opts.delta) if method=="hierarchical": if self.opts.order==None: error("Missing reuired option order") if len(self.opts.order)!=3: error("Order needs to be three characters") coeff["order"]=self.opts.order else: error("Method",method,"not yet implementes") gen=FoamFileGenerator(result) if self.opts.test: print_(str(gen)) return -1 else: f=open(path.join(case,"system","decomposeParDict"),"w") writeDictionaryHeader(f) f.write(str(gen)) f.close() if self.opts.clear: print_("Clearing processors") for p in glob(path.join(case,"processor*")): print_("Removing",p) rmtree(p,ignore_errors=True) self.checkAndCommit(SolutionDirectory(case,archive=None)) if self.opts.doDecompose: if self.opts.region: regionNames=self.opts.region[:] while True: try: i=regionNames.index("region0") regionNames[i]=None except ValueError: break else: regionNames=[None] regions=None sol=SolutionDirectory(case) if not decomposeParWithRegion: if self.opts.regions or self.opts.region!=None: print_("Building Pseudocases") regions=RegionCases(sol,clean=True,processorDirs=False) if self.opts.regions: regionNames=sol.getRegions(defaultRegion=True) for theRegion in regionNames: theCase=path.normpath(case) if theRegion!=None and not decomposeParWithRegion: theCase+="."+theRegion if oldApp(): argv=[self.opts.decomposer,".",theCase] else: argv=[self.opts.decomposer,"-case",theCase] if foamVersion()>=(2,0) and not self.opts.doFunctionObjects: argv+=["-noFunctionObjects"] if theRegion!=None and decomposeParWithRegion: argv+=["-region",theRegion] f=open(path.join(case,"system",theRegion,"decomposeParDict"),"w") writeDictionaryHeader(f) f.write(str(gen)) f.close() self.setLogname(default="Decomposer",useApplication=False) run=UtilityRunner(argv=argv, silent=self.opts.progress or self.opts.silent, logname=self.opts.logname, compressLog=self.opts.compress, server=self.opts.server, noLog=self.opts.noLog, logTail=self.opts.logTail, echoCommandLine=self.opts.echoCommandPrefix, jobId=self.opts.jobId) run.start() if theRegion!=None and not decomposeParWithRegion: print_("Syncing into master case") regions.resync(theRegion) if regions!=None and not decomposeParWithRegion: if not self.opts.keeppseudo: print_("Removing pseudo-regions") regions.cleanAll() else: for r in sol.getRegions(): if r not in regionNames: regions.clean(r) if self.opts.doConstantLinks: print_("Adding symlinks in the constant directories") constPath=path.join(case,"constant") for f in listdir(constPath): srcExpr=path.join(path.pardir,path.pardir,"constant",f) for p in range(nr): dest=path.join(case,"processor%d"%p,"constant",f) if not path.exists(dest): symlink(srcExpr,dest) self.addToCaseLog(case)
def run(self): config=ConfigParser.ConfigParser() files=self.parser.getArgs() good=config.read(files) # will work with 2.4 # if len(good)!=len(files): # print "Problem while trying to parse files",files # print "Only ",good," could be parsed" # sys.exit(-1) benchName=config.get("General","name") if self.opts.nameAddition!=None: benchName+="_"+self.opts.nameAddition if self.opts.foamVersion!=None: benchName+="_v"+self.opts.foamVersion isParallel=config.getboolean("General","parallel") lam=None if isParallel: nrCpus=config.getint("General","nProcs") machineFile=config.get("General","machines") if not path.exists(machineFile): self.error("Machine file ",machineFile,"needed for parallel run") lam=LAMMachine(machineFile,nr=nrCpus) if lam.cpuNr()>nrCpus: self.error("Wrong number of CPUs: ",lam.cpuNr()) print "Running parallel on",lam.cpuNr(),"CPUs" if config.has_option("General","casesDirectory"): casesDirectory=path.expanduser(config.get("General","casesDirectory")) else: casesDirectory=foamTutorials() if not path.exists(casesDirectory): self.error("Directory",casesDirectory,"needed with the benchmark cases is missing") else: print "Using cases from directory",casesDirectory benchCases=[] config.remove_section("General") for sec in config.sections(): print "Reading: ",sec skipIt=False skipReason="" if config.has_option(sec,"skip"): skipIt=config.getboolean(sec,"skip") skipReason="Switched off in file" if self.opts.excases!=None and not skipIt: for p in self.opts.excases: if fnmatch(sec,p): skipIt=True skipReason="Switched off by pattern '"+p+"'" if self.opts.cases!=None: for p in self.opts.cases: if fnmatch(sec,p): skipIt=False skipReason="" if skipIt: print "Skipping case ..... Reason:"+skipReason continue sol=config.get(sec,"solver") cas=config.get(sec,"case") pre=eval(config.get(sec,"prepare")) preCon=[] if config.has_option(sec,"preControlDict"): preCon=eval(config.get(sec,"preControlDict")) con=eval(config.get(sec,"controlDict")) bas=config.getfloat(sec,"baseline") wei=config.getfloat(sec,"weight") add=[] if config.has_option(sec,"additional"): add=eval(config.get(sec,"additional")) print "Adding: ", add util=[] if config.has_option(sec,"utilities"): util=eval(config.get(sec,"utilities")) print "Utilities: ", util nr=99999 if config.has_option(sec,"nr"): nr=eval(config.get(sec,"nr")) sp=None if config.has_option(sec,"blockSplit"): sp=eval(config.get(sec,"blockSplit")) toRm=[] if config.has_option(sec,"filesToRemove"): toRm=eval(config.get(sec,"filesToRemove")) setInit=[] if config.has_option(sec,"setInitial"): setInit=eval(config.get(sec,"setInitial")) parallelOK=False if config.has_option(sec,"parallelOK"): parallelOK=config.getboolean(sec,"parallelOK") deMet=["metis"] if config.has_option(sec,"decomposition"): deMet=config.get(sec,"decomposition").split() if deMet[0]=="metis": pass elif deMet[0]=="simple": if len(deMet)<2: deMet.append(0) else: deMet[1]=int(deMet[1]) else: print "Unimplemented decomposition method",deMet[0],"switching to metis" deMet=["metis"] if isParallel==False or parallelOK==True: if path.exists(path.join(casesDirectory,sol,cas)): benchCases.append( (nr,sec,sol,cas,pre,con,preCon,bas,wei,add,util,sp,toRm,setInit,deMet) ) else: print "Skipping",sec,"because directory",path.join(casesDirectory,sol,cas),"could not be found" else: print "Skipping",sec,"because not parallel" benchCases.sort() parallelString="" if isParallel: parallelString=".cpus="+str(nrCpus) resultFile=open("Benchmark."+benchName+"."+uname()[1]+parallelString+".results","w") totalSpeedup=0 minSpeedup=None maxSpeedup=None totalWeight =0 runsOK=0 currentEstimate = 1. print "\nStart Benching\n" csv=CSVCollection("Benchmark."+benchName+"."+uname()[1]+parallelString+".csv") # csvHeaders=["description","solver","case","caseDir","base", # "benchmark","machine","arch","cpus","os","version", # "wallclocktime","cputime","cputimeuser","cputimesystem","maxmemory","cpuusage","speedup"] for nr,description,solver,case,prepare,control,preControl,base,weight,additional,utilities,split,toRemove,setInit,decomposition in benchCases: # control.append( ("endTime",-2000) ) print "Running Benchmark: ",description print "Solver: ",solver print "Case: ",case caseName=solver+"_"+case+"_"+benchName+"."+uname()[1]+".case" print "Short name: ",caseName caseDir=caseName+".runDir" csv["description"]=description csv["solver"]=solver csv["case"]=case csv["caseDir"]=caseDir csv["base"]=base csv["benchmark"]=benchName csv["machine"]=uname()[1] csv["arch"]=uname()[4] if lam==None: csv["cpus"]=1 else: csv["cpus"]=lam.cpuNr() csv["os"]=uname()[0] csv["version"]=uname()[2] workDir=path.realpath(path.curdir) orig=SolutionDirectory(path.join(casesDirectory,solver,case), archive=None, paraviewLink=False) for a in additional+utilities: orig.addToClone(a) orig.cloneCase(path.join(workDir,caseDir)) if oldApp(): argv=[solver,workDir,caseDir] else: argv=[solver,"-case",path.join(workDir,caseDir)] run=BasicRunner(silent=True,argv=argv,logname="BenchRunning",lam=lam) runDir=run.getSolutionDirectory() controlFile=ParameterFile(runDir.controlDict()) for name,value in preControl: print "Setting parameter",name,"to",value,"in controlDict" controlFile.replaceParameter(name,value) for rm in toRemove: fn=path.join(caseDir,rm) print "Removing file",fn remove(fn) for field,bc,val in setInit: print "Setting",field,"on",bc,"to",val SolutionFile(runDir.initialDir(),field).replaceBoundary(bc,val) oldDeltaT=controlFile.replaceParameter("deltaT",0) for u in utilities: print "Building utility ",u execute("wmake 2>&1 >%s %s" % (path.join(caseDir,"BenchCompile."+u),path.join(caseDir,u))) print "Preparing the case: " if lam!=None: prepare=prepare+[("decomposePar","")] if decomposition[0]=="metis": lam.writeMetis(SolutionDirectory(path.join(workDir,caseDir))) elif decomposition[0]=="simple": lam.writeSimple(SolutionDirectory(path.join(workDir,caseDir)),decomposition[1]) if split: print "Splitting the mesh:",split bm=BlockMesh(runDir.blockMesh()) bm.refineMesh(split) for pre,post in prepare: print "Doing ",pre," ...." post=post.replace("%case%",caseDir) if oldApp(): args=string.split("%s %s %s %s" % (pre,workDir,caseDir,post)) else: args=string.split("%s -case %s %s" % (pre,path.join(workDir,caseDir),post)) util=BasicRunner(silent=True,argv=args,logname="BenchPrepare_"+pre) util.start() controlFile.replaceParameter("deltaT",oldDeltaT) # control.append(("endTime",-1000)) for name,value in control: print "Setting parameter",name,"to",value,"in controlDict" controlFile.replaceParameter(name,value) print "Starting at ",asctime(localtime(time())) print " Baseline is %f, estimated speedup %f -> estimated end at %s " % (base,currentEstimate,asctime(localtime(time()+base/currentEstimate))) print "Running the case ...." run.start() speedup=None cpuUsage=0 speedupOut=-1 try: speedup=base/run.run.wallTime() cpuUsage=100.*run.run.cpuTime()/run.run.wallTime() except ZeroDivisionError: print "Division by Zero: ",run.run.wallTime() if not run.runOK(): print "\nWARNING!!!!" print "Run had a problem, not using the results. Check the log\n" speedup=None if speedup!=None: speedupOut=speedup totalSpeedup+=speedup*weight totalWeight +=weight runsOK+=1 if maxSpeedup==None: maxSpeedup=speedup elif speedup>maxSpeedup: maxSpeedup=speedup if minSpeedup==None: minSpeedup=speedup elif speedup<minSpeedup: minSpeedup=speedup print "Wall clock: ",run.run.wallTime() print "Speedup: ",speedup," (Baseline: ",base,")" print "CPU Time: ",run.run.cpuTime() print "CPU Time User: "******"CPU Time System: ",run.run.cpuSystemTime() print "Memory: ",run.run.usedMemory() print "CPU Usage: %6.2f%%" % (cpuUsage) csv["wallclocktime"]=run.run.wallTime() csv["cputime"]=run.run.cpuTime() csv["cputimeuser"]=run.run.cpuUserTime() csv["cputimesystem"]=run.run.cpuSystemTime() csv["maxmemory"]=run.run.usedMemory() csv["cpuusage"]=cpuUsage if speedup!=None: csv["speedup"]=speedup else: csv["speedup"]="##" csv.write() resultFile.write("Case %s WallTime %g CPUTime %g UserTime %g SystemTime %g Memory %g MB Speedup %g\n" %(caseName,run.run.wallTime(),run.run.cpuTime(),run.run.cpuUserTime(),run.run.cpuSystemTime(),run.run.usedMemory(),speedupOut)) resultFile.flush() if speedup!=None: currentEstimate=totalSpeedup/totalWeight if self.opts.removeCases: print "Clearing case", if speedup==None: print "not ... because it failed" else: print "completely" rmtree(caseDir,ignore_errors=True) print print if lam!=None: lam.stop() print "Total Speedup: ",currentEstimate," ( ",totalSpeedup," / ",totalWeight, " ) Range: [",minSpeedup,",",maxSpeedup,"]" print runsOK,"of",len(benchCases),"ran OK" resultFile.write("Total Speedup: %g\n" % (currentEstimate)) if minSpeedup and maxSpeedup: resultFile.write("Range: [ %g , %g ]\n" % (minSpeedup,maxSpeedup)) resultFile.close()
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()
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()
def buildCase(self,cName,args): """Builds the case @param cName: The name of the case directory @param args: The arguments (as a dictionary)""" args=self.calculateVariables(args) os.mkdir(cName) for d in self.parameterTree().getElementsByTagName("directory"): dName=path.join(cName,d.getAttribute("name")) if not path.isdir(dName): os.mkdir(dName) sName=path.join(self.templatePath(),d.getAttribute("name")) for f in d.getElementsByTagName("file"): dFile=path.join(dName,f.getAttribute("name")) shutil.copy(path.join(sName,f.getAttribute("name")),dFile) if len(f.getElementsByTagName("parameter"))>0: pf=ParsedParameterFile(dFile) for p in f.getElementsByTagName("parameter"): pName=p.getAttribute("name") pValue=self.expandVars(p.getAttribute("value"),args) exec "pf"+pName+"="+pValue pf.writeFile() prep=self.getSingleElement(self.doc,"meshpreparation") util=prep.getElementsByTagName("utility") copy=self.getSingleElement(prep,"copy",optional=True) if len(util)>0 and copy: error("Copy and utilitiy mesh preparation specified") elif len(util)>0: for u in util: app=u.getAttribute("command") arg=self.expandVars(u.getAttribute("arguments"),args) argv=[app,"-case",cName]+arg.split() if oldApp(): argv[1]="." run=BasicRunner(argv=argv,silent=True,logname="CaseBuilder.prepareMesh."+app) run.start() if not run.runOK(): error(app,"failed. Check the logs") elif copy: source=self.expandVars(copy.getAttribute("template"),args) time=self.expandVars(copy.getAttribute("time"),args) if time=="": time="constant" shutil.copytree(path.join(source,time,"polyMesh"), path.join(cName,"constant","polyMesh")) else: error("Neither copy nor utilitiy mesh preparation specified") dName=path.join(cName,self.initialDir()) if not path.isdir(dName): os.mkdir(dName) sName=path.join(self.templatePath(),self.initialDir()) for f in self.fieldTree().getElementsByTagName("field"): dFile=path.join(dName,f.getAttribute("name")) shutil.copy(path.join(sName,f.getAttribute("name")),dFile) default=self.makeBC(self.getSingleElement(f,"defaultbc"),args) CreateBoundaryPatches(args=["--fix-types", "--overwrite", "--clear", "--default="+default, dFile]) bcDict={} bounds=self.boundaries() for b in f.getElementsByTagName("bc"): nm=b.getAttribute("name") if nm not in bounds: error("Boundary",nm,"not in list",bounds,"for field",f.getAttribute("name")) bcDict[nm]=b for name,pattern in self.boundaryPatterns(): if name in bcDict: default=self.makeBC(bcDict[name],args) CreateBoundaryPatches(args=["--filter="+pattern, "--overwrite", "--default="+default, dFile]) ic=self.expandVars(self.getSingleElement(f,"ic").getAttribute("value"),args) pf=ParsedParameterFile(dFile) pf["internalField"]="uniform "+ic pf.writeFile()
sol = SolutionDirectory(case) if not decomposeParWithRegion: if self.opts.regions or self.opts.region != None: print_("Building Pseudocases") regions = RegionCases(sol, clean=True, processorDirs=False) if self.opts.regions: regionNames = sol.getRegions(defaultRegion=True) for theRegion in regionNames: theCase = path.normpath(case) if theRegion != None and not decomposeParWithRegion: theCase += "." + theRegion if oldApp(): argv = [self.opts.decomposer, ".", theCase] else: argv = [self.opts.decomposer, "-case", theCase] if foamVersion() >= ( 2, 0) and not self.opts.doFunctionObjects: argv += ["-noFunctionObjects"] if theRegion != None and decomposeParWithRegion: argv += ["-region", theRegion] f = open( path.join(case, "system", theRegion, "decomposeParDict"), "w") writeDictionaryHeader(f) f.write(str(gen)) f.close()
def foamRun(self,application, args=[], foamArgs=[], steady=False, multiRegion=True, progress=False, compress=False, noLog=False): """Runs a foam utility on the case. If it is a parallel job and the grid has already been decomposed (and not yet reconstructed) it is run in parallel @param application: the Foam-Application that is to be run @param foamArgs: A list if with the additional arguments for the Foam-Application @param compress: Compress the log-file @param args: A list with additional arguments for the Runner-object @param steady: Use the steady-runner @param multiRegion: Run this on multiple regions (if None: I don't have an opinion on this) @param progress: Only output the time and nothing else @param noLog: Do not generate a logfile""" arglist=args[:] arglist+=["--job-id=%s" % self.fullJobId()] for k,v in iteritems(self.parameters): arglist+=["--parameter=%s:%s" % (str(k),str(v))] if self.isDecomposed and self.nproc>1: arglist+=["--procnr=%d" % self.nproc] if config().getboolean("ClusterJob","useMachineFile"): arglist+=["--machinefile=%s" % self.hostfile] arglist+=["--echo-command-prefix='=== Executing'"] if progress: arglist+=["--progress"] if noLog: arglist+=["--no-log"] if compress: arglist+=["--compress"] if self.multiRegion: if multiRegion: arglist+=["--all-regions"] elif multiRegion: warning("This is not a multi-region case, so trying to run stuff multi-region won't do any good") if self.restarted: arglist+=["--restart"] arglist+=[application] if oldApp(): arglist+=[".",self.casename()] else: arglist+=["-case",self.casename()] arglist+=foamArgs self.message("Executing",arglist) if steady: self.message("Running Steady") runner=SteadyRunner(args=arglist) else: runner=Runner(args=arglist)
def __init__(self, args=None, usage=None, version=None, description=None, epilog=None, examples=None, interspersed=False): """ :param usage: usage string. If missing a default is used :param version: if missing the PyFoam-version is used :param description: description of the utility :param epilog: Text to be displayed in the help after the options :param examples: Usage examples to be displayed after the epilog :param interspersed: needs to be false if options should be passed to an OpenFOAM-utility :param args: Command line arguments. If unset sys.argv[1:] is used. Can be a string: it will be splitted then unsing the spaces (very primitive), or a list of strings (prefered) """ if usage==None: if oldApp(): usage="%prog [options] <foamApplication> <caseDir> <caseName> [foamOptions]" else: usage="%prog [options] <foamApplication> [foamOptions]" if version==None: version="%prog "+versionString() if args==None: self.argLine=None elif type(args)==str: self.argLine=args.split() else: self.argLine=[str(a) for a in args] if examples: if epilog is None: epilog="" else: epilog+="\n\n" usageText="Usage examples:" # epilog+=usageText+"\n\n"+("="*len(usageText))+"\n\n"+examples epilog+=usageText+"\n\n"+examples OptionParser.__init__(self, usage=usage, # prog=self.__type__.__name__, version=version, description=description, epilog=epilog, formatter=FoamHelpFormatter()) if self.epilog: self.epilog=self.expand_prog_name(self.epilog) if interspersed: self.enable_interspersed_args() else: self.disable_interspersed_args() self.options=None self.args=None self.__foamVersionChanged=False self.__oldEnvironment=None
def buildCase(self, cName, args): """Builds the case @param cName: The name of the case directory @param args: The arguments (as a dictionary)""" args = self.calculateVariables(args) os.mkdir(cName) for d in self.parameterTree().getElementsByTagName("directory"): dName = path.join(cName, d.getAttribute("name")) if not path.isdir(dName): os.mkdir(dName) sName = path.join(self.templatePath(), d.getAttribute("name")) for f in d.getElementsByTagName("file"): dFile = path.join(dName, f.getAttribute("name")) shutil.copy(path.join(sName, f.getAttribute("name")), dFile) if len(f.getElementsByTagName("parameter")) > 0: pf = ParsedParameterFile(dFile) for p in f.getElementsByTagName("parameter"): pName = p.getAttribute("name") pValue = self.expandVars(p.getAttribute("value"), args) exec_("pf" + pName + "=" + pValue) pf.writeFile() prep = self.getSingleElement(self.doc, "meshpreparation") util = prep.getElementsByTagName("utility") copy = self.getSingleElement(prep, "copy", optional=True) if len(util) > 0 and copy: error("Copy and utilitiy mesh preparation specified") elif len(util) > 0: for u in util: app = u.getAttribute("command") arg = self.expandVars(u.getAttribute("arguments"), args) argv = [app, "-case", cName] + arg.split() if oldApp(): argv[1] = "." run = BasicRunner(argv=argv, silent=True, logname="CaseBuilder.prepareMesh." + app) run.start() if not run.runOK(): error(app, "failed. Check the logs") elif copy: source = self.expandVars(copy.getAttribute("template"), args) time = self.expandVars(copy.getAttribute("time"), args) if time == "": time = "constant" shutil.copytree(path.join(source, time, "polyMesh"), path.join(cName, "constant", "polyMesh")) else: error("Neither copy nor utilitiy mesh preparation specified") dName = path.join(cName, self.initialDir()) if not path.isdir(dName): os.mkdir(dName) sName = path.join(self.templatePath(), self.initialDir()) for f in self.fieldTree().getElementsByTagName("field"): dFile = path.join(dName, f.getAttribute("name")) shutil.copy(path.join(sName, f.getAttribute("name")), dFile) default = self.makeBC(self.getSingleElement(f, "defaultbc"), args) CreateBoundaryPatches(args=[ "--fix-types", "--overwrite", "--clear", "--default=" + default, dFile ]) bcDict = {} bounds = self.boundaries() for b in f.getElementsByTagName("bc"): nm = b.getAttribute("name") if nm not in bounds: error("Boundary", nm, "not in list", bounds, "for field", f.getAttribute("name")) bcDict[nm] = b for name, pattern in self.boundaryPatterns(): if name in bcDict: default = self.makeBC(bcDict[name], args) CreateBoundaryPatches(args=[ "--filter=" + pattern, "--overwrite", "--default=" + default, dFile ]) ic = self.expandVars( self.getSingleElement(f, "ic").getAttribute("value"), args) pf = ParsedParameterFile(dFile) pf["internalField"] = "uniform " + ic pf.writeFile()
def __init__(self, args=None, usage=None, version=None, description=None, epilog=None, examples=None, interspersed=False): """ @param usage: usage string. If missing a default is used @param version: if missing the PyFoam-version is used @param description: description of the utility @param epilog: Text to be displayed in the help after the options @param examples: Usage examples to be displayed after the epilog @param interspersed: needs to be false if options should be passed to an OpenFOAM-utility @param args: Command line arguments. If unset sys.argv[1:] is used. Can be a string: it will be splitted then unsing the spaces (very primitive), or a list of strings (prefered) """ if usage == None: if oldApp(): usage = "%prog [options] <foamApplication> <caseDir> <caseName> [foamOptions]" else: usage = "%prog [options] <foamApplication> [foamOptions]" if version == None: version = "%prog " + versionString() if args == None: self.argLine = None elif type(args) == str: self.argLine = args.split() else: self.argLine = map(str, args) if examples: if epilog is None: epilog = "" else: epilog += "\n\n" usageText = "Usage examples:" # epilog+=usageText+"\n\n"+("="*len(usageText))+"\n\n"+examples epilog += usageText + "\n\n" + examples OptionParser.__init__( self, usage=usage, # prog=self.__type__.__name__, version=version, description=description, epilog=epilog, formatter=FoamHelpFormatter()) if self.epilog: self.epilog = self.expand_prog_name(self.epilog) if interspersed: self.enable_interspersed_args() else: self.disable_interspersed_args() self.options = None self.args = None self.__foamVersionChanged = False self.__oldEnvironment = None
def run(self): config = ConfigParser.ConfigParser() files = self.parser.getArgs() good = config.read(files) # will work with 2.4 # if len(good)!=len(files): # print_("Problem while trying to parse files",files) # print_("Only ",good," could be parsed") # sys.exit(-1) benchName = config.get("General", "name") if self.opts.nameAddition != None: benchName += "_" + self.opts.nameAddition if self.opts.foamVersion != None: benchName += "_v" + self.opts.foamVersion isParallel = config.getboolean("General", "parallel") lam = None if isParallel: nrCpus = config.getint("General", "nProcs") machineFile = config.get("General", "machines") if not path.exists(machineFile): self.error("Machine file ", machineFile, "needed for parallel run") lam = LAMMachine(machineFile, nr=nrCpus) if lam.cpuNr() > nrCpus: self.error("Wrong number of CPUs: ", lam.cpuNr()) print_("Running parallel on", lam.cpuNr(), "CPUs") if config.has_option("General", "casesDirectory"): casesDirectory = path.expanduser( config.get("General", "casesDirectory")) else: casesDirectory = foamTutorials() if not path.exists(casesDirectory): self.error("Directory", casesDirectory, "needed with the benchmark cases is missing") else: print_("Using cases from directory", casesDirectory) benchCases = [] config.remove_section("General") for sec in config.sections(): print_("Reading: ", sec) skipIt = False skipReason = "" if config.has_option(sec, "skip"): skipIt = config.getboolean(sec, "skip") skipReason = "Switched off in file" if self.opts.excases != None and not skipIt: for p in self.opts.excases: if fnmatch(sec, p): skipIt = True skipReason = "Switched off by pattern '" + p + "'" if self.opts.cases != None: for p in self.opts.cases: if fnmatch(sec, p): skipIt = False skipReason = "" if skipIt: print_("Skipping case ..... Reason:" + skipReason) continue sol = config.get(sec, "solver") cas = config.get(sec, "case") pre = eval(config.get(sec, "prepare")) preCon = [] if config.has_option(sec, "preControlDict"): preCon = eval(config.get(sec, "preControlDict")) con = eval(config.get(sec, "controlDict")) bas = config.getfloat(sec, "baseline") wei = config.getfloat(sec, "weight") add = [] if config.has_option(sec, "additional"): add = eval(config.get(sec, "additional")) print_("Adding: ", add) util = [] if config.has_option(sec, "utilities"): util = eval(config.get(sec, "utilities")) print_("Utilities: ", util) nr = 99999 if config.has_option(sec, "nr"): nr = eval(config.get(sec, "nr")) sp = None if config.has_option(sec, "blockSplit"): sp = eval(config.get(sec, "blockSplit")) toRm = [] if config.has_option(sec, "filesToRemove"): toRm = eval(config.get(sec, "filesToRemove")) setInit = [] if config.has_option(sec, "setInitial"): setInit = eval(config.get(sec, "setInitial")) parallelOK = False if config.has_option(sec, "parallelOK"): parallelOK = config.getboolean(sec, "parallelOK") deMet = ["metis"] if config.has_option(sec, "decomposition"): deMet = config.get(sec, "decomposition").split() if deMet[0] == "metis": pass elif deMet[0] == "simple": if len(deMet) < 2: deMet.append(0) else: deMet[1] = int(deMet[1]) else: print_("Unimplemented decomposition method", deMet[0], "switching to metis") deMet = ["metis"] if isParallel == False or parallelOK == True: if path.exists(path.join(casesDirectory, sol, cas)): benchCases.append( (nr, sec, sol, cas, pre, con, preCon, bas, wei, add, util, sp, toRm, setInit, deMet)) else: print_("Skipping", sec, "because directory", path.join(casesDirectory, sol, cas), "could not be found") else: print_("Skipping", sec, "because not parallel") benchCases.sort() parallelString = "" if isParallel: parallelString = ".cpus=" + str(nrCpus) resultFile = open( "Benchmark." + benchName + "." + uname()[1] + parallelString + ".results", "w") totalSpeedup = 0 minSpeedup = None maxSpeedup = None totalWeight = 0 runsOK = 0 currentEstimate = 1. print_("\nStart Benching\n") csv = CSVCollection("Benchmark." + benchName + "." + uname()[1] + parallelString + ".csv") # csvHeaders=["description","solver","case","caseDir","base", # "benchmark","machine","arch","cpus","os","version", # "wallclocktime","cputime","cputimeuser","cputimesystem","maxmemory","cpuusage","speedup"] for nr, description, solver, case, prepare, control, preControl, base, weight, additional, utilities, split, toRemove, setInit, decomposition in benchCases: # control.append( ("endTime",-2000) ) print_("Running Benchmark: ", description) print_("Solver: ", solver) print_("Case: ", case) caseName = solver + "_" + case + "_" + benchName + "." + uname( )[1] + ".case" print_("Short name: ", caseName) caseDir = caseName + ".runDir" csv["description"] = description csv["solver"] = solver csv["case"] = case csv["caseDir"] = caseDir csv["base"] = base csv["benchmark"] = benchName csv["machine"] = uname()[1] csv["arch"] = uname()[4] if lam == None: csv["cpus"] = 1 else: csv["cpus"] = lam.cpuNr() csv["os"] = uname()[0] csv["version"] = uname()[2] workDir = path.realpath(path.curdir) orig = SolutionDirectory(path.join(casesDirectory, solver, case), archive=None, paraviewLink=False) for a in additional + utilities: orig.addToClone(a) orig.cloneCase(path.join(workDir, caseDir)) if oldApp(): argv = [solver, workDir, caseDir] else: argv = [solver, "-case", path.join(workDir, caseDir)] run = BasicRunner(silent=True, argv=argv, logname="BenchRunning", lam=lam) runDir = run.getSolutionDirectory() controlFile = ParameterFile(runDir.controlDict()) for name, value in preControl: print_("Setting parameter", name, "to", value, "in controlDict") controlFile.replaceParameter(name, value) for rm in toRemove: fn = path.join(caseDir, rm) print_("Removing file", fn) remove(fn) for field, bc, val in setInit: print_("Setting", field, "on", bc, "to", val) SolutionFile(runDir.initialDir(), field).replaceBoundary(bc, val) oldDeltaT = controlFile.replaceParameter("deltaT", 0) for u in utilities: print_("Building utility ", u) execute("wmake 2>&1 >%s %s" % (path.join( caseDir, "BenchCompile." + u), path.join(caseDir, u))) print_("Preparing the case: ") if lam != None: prepare = prepare + [("decomposePar", "")] if decomposition[0] == "metis": lam.writeMetis( SolutionDirectory(path.join(workDir, caseDir))) elif decomposition[0] == "simple": lam.writeSimple( SolutionDirectory(path.join(workDir, caseDir)), decomposition[1]) if split: print_("Splitting the mesh:", split) bm = BlockMesh(runDir.blockMesh()) bm.refineMesh(split) for pre, post in prepare: print_("Doing ", pre, " ....") post = post.replace("%case%", caseDir) if oldApp(): args = string.split("%s %s %s %s" % (pre, workDir, caseDir, post)) else: args = string.split( "%s -case %s %s" % (pre, path.join(workDir, caseDir), post)) util = BasicRunner(silent=True, argv=args, logname="BenchPrepare_" + pre) util.start() controlFile.replaceParameter("deltaT", oldDeltaT) # control.append(("endTime",-1000)) for name, value in control: print_("Setting parameter", name, "to", value, "in controlDict") controlFile.replaceParameter(name, value) print_("Starting at ", asctime(localtime(time()))) print_( " Baseline is %f, estimated speedup %f -> estimated end at %s " % (base, currentEstimate, asctime(localtime(time() + base / currentEstimate)))) print_("Running the case ....") run.start() speedup = None cpuUsage = 0 speedupOut = -1 try: speedup = base / run.run.wallTime() cpuUsage = 100. * run.run.cpuTime() / run.run.wallTime() except ZeroDivisionError: print_("Division by Zero: ", run.run.wallTime()) if not run.runOK(): print_("\nWARNING!!!!") print_( "Run had a problem, not using the results. Check the log\n" ) speedup = None if speedup != None: speedupOut = speedup totalSpeedup += speedup * weight totalWeight += weight runsOK += 1 if maxSpeedup == None: maxSpeedup = speedup elif speedup > maxSpeedup: maxSpeedup = speedup if minSpeedup == None: minSpeedup = speedup elif speedup < minSpeedup: minSpeedup = speedup print_("Wall clock: ", run.run.wallTime()) print_("Speedup: ", speedup, " (Baseline: ", base, ")") print_("CPU Time: ", run.run.cpuTime()) print_("CPU Time User: "******"CPU Time System: ", run.run.cpuSystemTime()) print_("Memory: ", run.run.usedMemory()) print_("CPU Usage: %6.2f%%" % (cpuUsage)) csv["wallclocktime"] = run.run.wallTime() csv["cputime"] = run.run.cpuTime() csv["cputimeuser"] = run.run.cpuUserTime() csv["cputimesystem"] = run.run.cpuSystemTime() csv["maxmemory"] = run.run.usedMemory() csv["cpuusage"] = cpuUsage if speedup != None: csv["speedup"] = speedup else: csv["speedup"] = "##" csv.write() resultFile.write( "Case %s WallTime %g CPUTime %g UserTime %g SystemTime %g Memory %g MB Speedup %g\n" % (caseName, run.run.wallTime(), run.run.cpuTime(), run.run.cpuUserTime(), run.run.cpuSystemTime(), run.run.usedMemory(), speedupOut)) resultFile.flush() if speedup != None: currentEstimate = totalSpeedup / totalWeight if self.opts.removeCases: print_("Clearing case", end=" ") if speedup == None: print_("not ... because it failed") else: print_("completely") rmtree(caseDir, ignore_errors=True) print_() print_()