I am trying calculate the number of Floating point operations per second that my CPU can perform, so I wrote the following program:
import time
import sys
from multiprocessing import Process
numOfLoops = 10000000
if (len(sys.argv) != 2):
print "Correct Usage: python cpu.py 'no_of_processes'"
sys.exit()
#function for each process
def fpOps():
a = float(0.0)
for i in xrange(0, numOfLoops):
a += 0.5
#print a #for debugging purpose
processes = []
numOfProcesses = int(sys.argv[1])
numOfOps = numOfLoops * numOfProcesses
for i in xrange(0, numOfProcesses):
processes.append(Process(target=fpOps))
start = time.time()
for process in processes:
process.start()
for process in processes:
process.join()
end = time.time()
execTime = end - start
print "Exec Time " , execTime
FLOPS = (float(numOfOps/execTime))
print "FLOPS : " , FLOPS
The program calculates the time (execTime) it takes to perform 'n' number of floating point operations and 'n / execTime' gives me the FLOPS value I want.
But, the FLOPS value decreases as I increase the number the processes. I was expecting it to reduce since the processes are performing more number of operations per second because they run in parallel. What am I doing wrong??