python - Using multiprocessing to utilize all cores of the CPU -


i trying calculate number of floating point operations per second cpu can perform, wrote following program:

import time import sys multiprocessing import process   numofloops = 10000000  if (len(sys.argv) != 2):     print "correct usage: python cpu.py 'no_of_processes'"     sys.exit()  #function each process def fpops():     = float(0.0)     in xrange(0, numofloops):         += 0.5         #print #for debugging purpose  processes = [] numofprocesses = int(sys.argv[1]) numofops = numofloops * numofprocesses  in xrange(0, numofprocesses):     processes.append(process(target=fpops))  start = time.time() process in processes:     process.start() 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 time (exectime) takes perform 'n' number of floating point operations , 'n / exectime' gives me flops value want.

but, flops value decreases increase number processes. expecting reduce since processes performing more number of operations per second because run in parallel. doing wrong??


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -