1 year ago
#361595
Jordan RIchard
Looking to Maximize CPU Utilization with a python benchmarking program using concurrent.futures
I have been working on developing a synthetic benchmarking program in python in order to stress-test the CPU in various systems for a class project. I have based my approach on Mersenne primality tests (inspired by prime95). The program is intended to test the Mersenne primality of numbers over a working set, defined by the user. I have so far implemented this in python, however once implementing the concurrent.futures module in order to run the task in parallel to maximize CPU utilization, I hit a snag. When testing my program I ran into 2 issues.
- CPU utilization is still only ~35%
- When testing larger working sets, the program stalls for several minutes before it starts iterating through each prime - I am assuming this has something to do with concurrent.futures's setup.
I was hoping someone could provide some insight into how to maximize system resource usage with this program and iron out the issues with larger sets.
Code below:
sys = platform.uname()
c = wmi.WMI()
winSys = c.Win32_ComputerSystem()[0]
mode1 = "Integer Mode"
mode2 = "Floating-Point Mode"
def lehmer(p: int) -> bool:
s = 4
M = (1 << p) - 1
for i in range(p - 2):
s = ((s * s) - 2) % M
return s == 0
#Initial printout of system information and menu screen schowing benchamrking options
print("_________________________________________________________________________________")
print("------------------------------System Information---------------------------------")
print(f"\tOS: {sys.system} {sys.release} ") #
print(f"\tMachine Name: {sys.node}")
print(f"\tVersion: {sys.version}")
print(f"\tCPU: {sys.processor}")
print("\tNumber of Cores: " + str(psutil.cpu_count()))
print(f"\tRAM: {psutil.virtual_memory()}")
print("---------------------------------------------------------------------------------")
modeSelect = 0;
print("Welcome to ParaBench! Please select what benchmarking mode you would like to use." + '\n')
modeSelect = int(input("[1] -> " + mode1 + '\n' + "[2] -> " + mode2
+ "\n[9] -> Exit\n_________________________________________________________________________________\n"))
#User selects Integer benchmarking mode
if modeSelect == 1:
print("User Selected " + mode1)
#Printout of selection for order of magnitude
print("[1] -> First 1x10^2 Primes\n" + "[2] -> First 1x10^3 Primes\n"
+"[3] -> First 1x10^4 Primes\n" + "[4] -> First 1x10^5 Primes\n" + "[5] -> First 1x10^6 Primes\n")
mersenneOrder = int(input("Please Select an option\n"))
if mersenneOrder == 1:
print("Starting Benchmark...")
with ThreadPoolExecutor(15) as executor:
timeStart = perf_counter()
for result in executor.map(lehmer,range(2,100)):
print(result)
timeStop = perf_counter()
print("1E2 Benchmark Complete in ",timeStop-timeStart)
if mersenneOrder == 2:
print("Starting Benchmark...")
with ThreadPoolExecutor(15) as executor:
timeStart = perf_counter()
for result in executor.map(lehmer,range(2,1000)):
print(result)
timeStop = perf_counter()
print("1E3 Benchmark Complete!!", timeStop-timeStart)
if mersenneOrder == 3:
print("Starting Benchmark...")
with ThreadPoolExecutor() as executor:
timeStart = perf_counter()
for result in executor.map(lehmer,range(2,10000)):
print(result)
timeStop = perf_counter()
print("1E4 Benchmark Complete!!", timeStop-timeStart)
if mersenneOrder == 4:
print("Starting Benchmark...")
with ThreadPoolExecutor(15) as executor:
timeStart = perf_counter()
for result in executor.map(lehmer,range(2,100000)):
print(result)
timeStop = perf_counter()
print("1E5 Benchmark Complete!!", timeStop-timeStart)
if mersenneOrder == 5:
print("Starting Benchmark...")
with ThreadPoolExecutor(15) as executor:
timeStart = perf_counter()
for result in executor.map(lehmer,range(2,1000000)):
print(result)
timeStop = perf_counter()
print("1E6 Benchmark Complete!!", timeStop-timeStart)
#Single-threaded test (DEPRECATED)
#for x in range(2,1000000):
# if lehmer(x):
# print(x)
python
performance
benchmarking
concurrent.futures
stress-testing
0 Answers
Your Answer