Skip to content

Commit ab94183

Browse files
committedJan 19, 2021
[pbbs] Update runTests.py for Python3
1 parent 063cba4 commit ab94183

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed
 

‎pbbs/common/runTests.py

+23-22
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
import os
55

66
def onPprocessors(command,p) :
7-
if os.environ.has_key("OPENMP"):
7+
if "OPENMP" in os.environ:
88
os.putenv("OMP_NUM_THREADS", "%d" %p)
99
return command
10-
elif os.environ.has_key("GCILK") or os.environ.has_key("CCILK") or os.environ.has_key("ICC"):
11-
return "export CILK_NWORKERS="+`p`+"; " + command
12-
elif os.environ.has_key("CILK"):
13-
return command + " -cilk_set_worker_count " + `p`
14-
elif os.environ.has_key("MKLROOT"):
15-
return "export CILK_NWORKERS="+`p`+"; " + command
10+
elif "GCILK" in os.environ or "CCILK" in os.environ or "ICC" in os.environ:
11+
return "export CILK_NWORKERS="+str(p)+"; " + command
12+
elif "CILK" in os.environ:
13+
return command + " -cilk_set_worker_count " + str(p)
14+
elif "MKLROOT" in os.environ:
15+
return "export CILK_NWORKERS="+str(p)+"; " + command
1616
return command
1717

18-
def shellGetOutput(str) :
19-
process = subprocess.Popen(str,shell=True,stdout=subprocess.PIPE,
18+
def shellGetOutput(cmd) :
19+
process = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
2020
stderr=subprocess.PIPE)
2121
output, err = process.communicate()
2222

2323
if (len(err) > 0):
24-
raise NameError(str+"\n"+output+err)
25-
return output
24+
raise NameError(cmd+"\n"+output.decode("utf-8")+err.decode("utf-8"))
25+
return output.decode("utf-8")
2626

2727
def stripFloat(val) :
2828
trunc = float(int(val*1000))/1000
@@ -32,6 +32,7 @@ def runSingle(runProgram, options, ifile, procs) :
3232
comString = "./"+runProgram+" "+options+" "+ifile
3333
if (procs > 0) :
3434
comString = onPprocessors(comString,procs)
35+
#print(comString)
3536
out = shellGetOutput(comString)
3637
#print(out)
3738
try:
@@ -43,7 +44,7 @@ def runSingle(runProgram, options, ifile, procs) :
4344
def runTest(runProgram, checkProgram, dataDir, test, rounds, procs, noOutput) :
4445
random.seed()
4546
tmpdir="/tmp"
46-
if os.environ.has_key("TMPDIR"):
47+
if "TMPDIR" in os.environ:
4748
tmpdir = os.getenv("TMPDIR")
4849
outFile="%s/ofile%d_%d" %(tmpdir, random.randint(0, 1000000), random.randint(0, 1000000))
4950
[weight, inputFileNames, runOptions, checkOptions] = test
@@ -53,7 +54,7 @@ def runTest(runProgram, checkProgram, dataDir, test, rounds, procs, noOutput) :
5354
if len(dataDir)>0:
5455
out = shellGetOutput("cd " + dataDir + "; make " + shortInputNames)
5556
longInputNames = " ".join(dataDir + "/" + name for name in inputFileNames)
56-
runOptions = runOptions + " -r " + `rounds`
57+
runOptions = runOptions + " -r " + str(rounds)
5758
if (noOutput == 0) :
5859
runOptions = runOptions + " -o " + outFile
5960
times = runSingle(runProgram, runOptions, longInputNames, procs)
@@ -72,7 +73,7 @@ def runTest(runProgram, checkProgram, dataDir, test, rounds, procs, noOutput) :
7273
outputStr = ""
7374
if (len(runOptions) > 0) :
7475
outputStr = " : " + runOptions
75-
print(`weight` + " : " + shortInputNames + outputStr + " : "
76+
print(str(weight) + " : " + shortInputNames + outputStr + " : "
7677
+ ptimes)
7778
return [weight,times]
7879

@@ -101,10 +102,10 @@ def timeAll(name, runProgram, checkProgram, dataDir, tests, rounds, procs, noOut
101102
times = sorted(times)
102103
totalTimeMean = totalTimeMean + weight*sum(times)/l
103104
totalTimeMin = totalTimeMin + weight*times[0]
104-
totalTimeMedian = totalTimeMedian + weight*times[(l-1)/2]
105+
totalTimeMedian = totalTimeMedian + weight*times[(l-1)//2]
105106
totalWeight = totalWeight + weight
106107
j += 1
107-
print(name + " : " + `procs` +" : " +
108+
print(name + " : " + str(procs) +" : " +
108109
"weighted time, min=" + stripFloat(totalTimeMin/totalWeight) +
109110
" median=" + stripFloat(totalTimeMedian/totalWeight) +
110111
" mean=" + stripFloat(totalTimeMean/totalWeight))
@@ -116,9 +117,9 @@ def timeAll(name, runProgram, checkProgram, dataDir, tests, rounds, procs, noOut
116117
print("Could not insert result in database. Error:", sys.exc_info()[0])
117118
# if (os.getlogin() == 'akyrola'): raise
118119
return 0
119-
except NameError,v:
120-
x, = v
121-
print "TEST TERMINATED ABNORMALLY:\n["+x + "]"
120+
except NameError as v:
121+
x, = v.args
122+
print("TEST TERMINATED ABNORMALLY:\n["+x + "]")
122123
return 1
123124
except KeyboardInterrupt:
124125
return 1
@@ -243,7 +244,7 @@ def getHostId():
243244

244245
(sysname, nodename, release, version, machine) = os.uname()
245246

246-
if (os.environ.has_key("OPENMP")):
247+
if "OPENMP" in os.environ:
247248
nodename = nodename + "[OPENMP]"
248249

249250
cursor.execute("select id from pbbs_hosts where hostname=%s and procmodel=%s and version=%s and numprocs=%s", (nodename, procmodel, version, numprocs))
@@ -279,15 +280,15 @@ def detectCPUs():
279280
"""
280281
# Linux, Unix and MacOS:
281282
if hasattr(os, "sysconf"):
282-
if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
283+
if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
283284
# Linux & Unix:
284285
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
285286
if isinstance(ncpus, int) and ncpus > 0:
286287
return ncpus
287288
else: # OSX:
288289
return int(os.popen2("sysctl -n hw.ncpu")[1].read())
289290
# Windows:
290-
if os.environ.has_key("NUMBER_OF_PROCESSORS"):
291+
if "NUMBER_OF_PROCESSORS" in os.environ:
291292
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
292293
if ncpus > 0:
293294
return ncpus

0 commit comments

Comments
 (0)
Please sign in to comment.