0

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??

Rakesh Adhikesavan
  • 11,966
  • 18
  • 51
  • 76
  • Are you saying FLOPS gets smaller as numOfProcesses gets bigger or smaller? – Padraic Cunningham Feb 07 '16 at 21:59
  • FLOPS gets smaller as numOfProcesses gets bigger – Rakesh Adhikesavan Feb 07 '16 at 22:01
  • Since it wasn't really an answer, I'm posting it here: You don't take into account the time it takes for the system to initialise concurrency, sending jobs, executing them, and getting them back to you! Here is an excellent tutorial from David Beazley on concurrency in Python: https://www.youtube.com/watch?v=MCs5OvhV9S4 – Pouria Feb 07 '16 at 22:03
  • processes are expensive to create, adding more does not mean mean faster. You see a decrease as you spend more time creating the processes – Padraic Cunningham Feb 07 '16 at 22:04
  • I am aware there is an overhead that will cause a discrepancy in my FLOPS value. But my FLOPS value is no where close to the theoretical value.... Is there a better way I can attempt to benchmark my CPU? – Rakesh Adhikesavan Feb 07 '16 at 22:05
  • What have you calculate it should be? – Padraic Cunningham Feb 07 '16 at 22:16
  • https://en.wikipedia.org/wiki/Benchmark_(computing)#Open_source_benchmarks – Padraic Cunningham Feb 07 '16 at 22:26
  • 1
    I couldn't reproduce on my 2 cpu system (hey, don't laugh). For 1, 2 and 8 I got 7130236, 13781727 and 13522182. That's roughly scaling up with cpus and then gradually decaying because of processor contention. – tdelaney Feb 08 '16 at 00:18

0 Answers0