4
4
import os
5
5
6
6
def onPprocessors (command ,p ) :
7
- if os . environ . has_key ( "OPENMP" ) :
7
+ if "OPENMP" in os . environ :
8
8
os .putenv ("OMP_NUM_THREADS" , "%d" % p )
9
9
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
16
16
return command
17
17
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 ,
20
20
stderr = subprocess .PIPE )
21
21
output , err = process .communicate ()
22
22
23
23
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" )
26
26
27
27
def stripFloat (val ) :
28
28
trunc = float (int (val * 1000 ))/ 1000
@@ -32,6 +32,7 @@ def runSingle(runProgram, options, ifile, procs) :
32
32
comString = "./" + runProgram + " " + options + " " + ifile
33
33
if (procs > 0 ) :
34
34
comString = onPprocessors (comString ,procs )
35
+ #print(comString)
35
36
out = shellGetOutput (comString )
36
37
#print(out)
37
38
try :
@@ -43,7 +44,7 @@ def runSingle(runProgram, options, ifile, procs) :
43
44
def runTest (runProgram , checkProgram , dataDir , test , rounds , procs , noOutput ) :
44
45
random .seed ()
45
46
tmpdir = "/tmp"
46
- if os . environ . has_key ( "TMPDIR" ) :
47
+ if "TMPDIR" in os . environ :
47
48
tmpdir = os .getenv ("TMPDIR" )
48
49
outFile = "%s/ofile%d_%d" % (tmpdir , random .randint (0 , 1000000 ), random .randint (0 , 1000000 ))
49
50
[weight , inputFileNames , runOptions , checkOptions ] = test
@@ -53,7 +54,7 @@ def runTest(runProgram, checkProgram, dataDir, test, rounds, procs, noOutput) :
53
54
if len (dataDir )> 0 :
54
55
out = shellGetOutput ("cd " + dataDir + "; make " + shortInputNames )
55
56
longInputNames = " " .join (dataDir + "/" + name for name in inputFileNames )
56
- runOptions = runOptions + " -r " + ` rounds`
57
+ runOptions = runOptions + " -r " + str ( rounds )
57
58
if (noOutput == 0 ) :
58
59
runOptions = runOptions + " -o " + outFile
59
60
times = runSingle (runProgram , runOptions , longInputNames , procs )
@@ -72,7 +73,7 @@ def runTest(runProgram, checkProgram, dataDir, test, rounds, procs, noOutput) :
72
73
outputStr = ""
73
74
if (len (runOptions ) > 0 ) :
74
75
outputStr = " : " + runOptions
75
- print (` weight` + " : " + shortInputNames + outputStr + " : "
76
+ print (str ( weight ) + " : " + shortInputNames + outputStr + " : "
76
77
+ ptimes )
77
78
return [weight ,times ]
78
79
@@ -101,10 +102,10 @@ def timeAll(name, runProgram, checkProgram, dataDir, tests, rounds, procs, noOut
101
102
times = sorted (times )
102
103
totalTimeMean = totalTimeMean + weight * sum (times )/ l
103
104
totalTimeMin = totalTimeMin + weight * times [0 ]
104
- totalTimeMedian = totalTimeMedian + weight * times [(l - 1 )/ 2 ]
105
+ totalTimeMedian = totalTimeMedian + weight * times [(l - 1 )// 2 ]
105
106
totalWeight = totalWeight + weight
106
107
j += 1
107
- print (name + " : " + ` procs` + " : " +
108
+ print (name + " : " + str ( procs ) + " : " +
108
109
"weighted time, min=" + stripFloat (totalTimeMin / totalWeight ) +
109
110
" median=" + stripFloat (totalTimeMedian / totalWeight ) +
110
111
" mean=" + stripFloat (totalTimeMean / totalWeight ))
@@ -116,9 +117,9 @@ def timeAll(name, runProgram, checkProgram, dataDir, tests, rounds, procs, noOut
116
117
print ("Could not insert result in database. Error:" , sys .exc_info ()[0 ])
117
118
# if (os.getlogin() == 'akyrola'): raise
118
119
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 + "]" )
122
123
return 1
123
124
except KeyboardInterrupt :
124
125
return 1
@@ -243,7 +244,7 @@ def getHostId():
243
244
244
245
(sysname , nodename , release , version , machine ) = os .uname ()
245
246
246
- if ( os . environ . has_key ( "OPENMP" )) :
247
+ if "OPENMP" in os . environ :
247
248
nodename = nodename + "[OPENMP]"
248
249
249
250
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():
279
280
"""
280
281
# Linux, Unix and MacOS:
281
282
if hasattr (os , "sysconf" ):
282
- if os . sysconf_names . has_key ( "SC_NPROCESSORS_ONLN" ) :
283
+ if "SC_NPROCESSORS_ONLN" in os . sysconf_names :
283
284
# Linux & Unix:
284
285
ncpus = os .sysconf ("SC_NPROCESSORS_ONLN" )
285
286
if isinstance (ncpus , int ) and ncpus > 0 :
286
287
return ncpus
287
288
else : # OSX:
288
289
return int (os .popen2 ("sysctl -n hw.ncpu" )[1 ].read ())
289
290
# Windows:
290
- if os . environ . has_key ( "NUMBER_OF_PROCESSORS" ) :
291
+ if "NUMBER_OF_PROCESSORS" in os . environ :
291
292
ncpus = int (os .environ ["NUMBER_OF_PROCESSORS" ]);
292
293
if ncpus > 0 :
293
294
return ncpus
0 commit comments