2020
2121#Third-party packages
2222import cpuinfo
23+ from numba import njit , prange
2324import psutil
2425import GPUtil
2526import distro
@@ -48,6 +49,9 @@ def is_connected():
4849 except requests .ConnectionError :
4950 return False
5051
52+ except :
53+ return False
54+
5155
5256def return_api_key ():
5357 if os .path .exists ("apikey.txt" ):
@@ -317,7 +321,7 @@ def distroColour():
317321 quit ()
318322
319323 #UPDATE THIS WITH EVERY VERSION
320- version = "1.6.0 "
324+ version = "1.6.1 "
321325 #UPDATE THIS WITH EVERY VERSION
322326
323327 endLoad = True
@@ -1099,57 +1103,52 @@ def run_processes():
10991103
11001104 return score , gflops , full_load_score
11011105
1106+ @njit (nogil = True )
1107+ def run_simulation (ballHeight = 1000.0 , acceleration = 9.81 , dt = 1e-6 ):
1108+ t = 0.0
1109+ y = 0.0
1110+ vy = 0.0
1111+ x = 0.0
1112+ vx = 50.0
1113+ total = 0.0
1114+
1115+ # bounce multiple times to increase load
1116+ for bounce in range (10 ):
1117+ y = 0.0
1118+ t = 0.0
1119+ vy = 0.0
1120+ while y < ballHeight :
1121+ vy -= acceleration * dt
1122+ t += dt
1123+ y = 0.5 * acceleration * t * t
1124+ x += vx * dt
1125+
1126+ # additional stress
1127+ angle = math .atan2 (vy , vx )
1128+ mag = math .sqrt (vy ** 2 + vx ** 2 )
1129+ total += math .sin (angle ) * mag + math .cos (angle ) * mag
1130+
1131+ return total
11021132
11031133def multiThread (showResults ):
11041134 logical_cores = os .cpu_count ()
11051135 p = psutil .Process (os .getpid ())
11061136 p .cpu_affinity (list (range (logical_cores )))
11071137
1108- def intense1 (procNo , timeList , core_id , core_show , thread_id , thread_pass ):
1109- p = psutil .Process (os .getpid ())
1110- p .cpu_affinity ([core_id ])
1111- print (f"[{ colours .magenta ()} { procNo } -rT{ colours .reset ()} -{ colours .magenta ()} [p]{ thread_pass } { colours .reset ()} ] Crunching numbers..." )
1112- ballHeight = 250
1113- acceleration = 9.81 + random .randint (- 10 , 10 ) / 10
1114- ballConstant = random .randint (1 , 10 )
1115- timeSimulated = 0
1116- timeIncrement = 1e-6
1117- distanceTravelled = 0
1118- yVel = 0
1119- while distanceTravelled < ballHeight :
1120- yVel -= timeIncrement * acceleration
1121- timeSimulated += timeIncrement
1122- distanceTravelled = 0.5 * acceleration * timeSimulated ** 2
1123- yVel = - yVel - ballConstant
1124- timeList .append (timeSimulated )
1125- print (f"[{ colours .green ()} { procNo } -cT{ colours .reset ()} ] Instance complete!" )
1138+ if dynamicMode :
1139+ threadCount = Threads
1140+ else :
1141+ threadCount = 12
11261142
1127- def intense2 (procNo , timeList , core_id , core_show , thread_id , thread_pass ):
1143+ def intense_thread (procNo , timeList , core_id , core_show , thread_id , thread_pass , timeList_lock ):
11281144 p = psutil .Process (os .getpid ())
11291145 p .cpu_affinity ([core_id ])
11301146 print (f"[{ colours .magenta ()} { procNo } -rT{ colours .reset ()} -{ colours .magenta ()} [p]{ thread_pass } { colours .reset ()} ] Crunching numbers..." )
1131- arrowHeight = 250
1132- ACCELERATION = 9.81 + random .randint (- 10 , 10 ) / 10
1133- timeSimulated = 0
1134- timeIncrement = 1e-6
1135- yDistanceTravelled = 0
1136- xVel = 50
1137- yVel = 0
1138- while yDistanceTravelled < arrowHeight :
1139- yVel -= timeIncrement * ACCELERATION
1140- timeSimulated += timeIncrement
1141- yDistanceTravelled = 0.5 * ACCELERATION * timeSimulated ** 2
1142- xDistanceTravelled = xVel * timeSimulated
1143- angle = - math .atan2 (yVel , xVel ) * (180 / math .pi )
1144- resultantVelocity = math .sqrt (yVel ** 2 + xVel ** 2 )
1145- timeList .append (timeSimulated )
1147+ result = run_simulation ()
1148+ with timeList_lock :
1149+ timeList .append (result )
11461150 print (f"[{ colours .green ()} { procNo } -cT{ colours .reset ()} ] Instance complete!" )
11471151
1148- if dynamicMode :
1149- threadCount = Threads
1150- else :
1151- threadCount = 12
1152-
11531152 def run_threads ():
11541153 work_queue = queue .Queue ()
11551154 timeList = []
@@ -1163,18 +1162,15 @@ def run_threads():
11631162 core_show = logical_id // 2
11641163 thread_id = logical_id % 2
11651164 thread_pass = i // total_logical_threads
1166- if proc_no % 2 == 0 :
1167- work_queue .put ((intense1 , proc_no , timeList , logical_id , core_show , thread_id , thread_pass ))
1168- else :
1169- work_queue .put ((intense2 , proc_no , timeList , logical_id , core_show , thread_id , thread_pass ))
1165+ work_queue .put ((proc_no , logical_id , core_show , thread_id , thread_pass ))
11701166
11711167 def worker ():
11721168 while True :
11731169 try :
1174- func , proc_no , timeList , logical_id , core_show , thread_id , thread_pass = work_queue .get (block = False )
1170+ proc_no , logical_id , core_show , thread_id , thread_pass = work_queue .get (block = False )
11751171 except queue .Empty :
11761172 break
1177- func (proc_no , timeList , logical_id , core_show , thread_id , thread_pass )
1173+ intense_thread (proc_no , timeList , logical_id , core_show , thread_id , thread_pass , timeList_lock )
11781174 work_queue .task_done ()
11791175
11801176 threads = []
@@ -1206,9 +1202,9 @@ def worker():
12061202 avgTime = totalTime / 3
12071203
12081204 if dynamicMode :
1209- score = round ((1 / (avgTime / (math .e / 1.5 ))* (math .e )* (1000 * ( 1 / math .log (threadCount ,10 )))))
1205+ score = round ((1 / (avgTime / (math .e / 1.5 )) * (math .e ) * (1000 * ( 1 / math .log (threadCount , 10 )))))
12101206 else :
1211- score = round ((1 / (avgTime / (math .e / 1.5 ))* (math .e )* (1000 * ( 1 / math .log ( threadCount - 6 , 10 ) ))))
1207+ score = round ((( 1 / (avgTime / (math .e / 1.5 )) * (math .e ) * (1000 * math .e * 1.5 ))))
12121208
12131209 clear ()
12141210
@@ -1367,7 +1363,12 @@ def avg(colName):
13671363 if not dynamicMode and apikey :
13681364 status = upload_and_return_status (brandName , systemCoreCount , Threads , memRaw , singleCoreScore , multiCoreScore , multiThreadScore , gflops , fullLoadScore , finalScore , distroName , version , apikey )
13691365
1370- while "invalid api key" in status .lower ():
1366+ status = str (status )
1367+
1368+ if not status :
1369+ status = ""
1370+
1371+ while "invalid api key" in status .lower () and return_api_key ():
13711372 request_invalid_key ()
13721373
13731374
0 commit comments