if __name__ == '__main__':
arr = loadtxt("c:\\train_save.csv", delimiter=',', usecols=(3, 4, 5))
start = 0
end = len(arr)
print type(arr)
ppservers = ()
#job_server = pp.Server(ncpus, ppservers=ppservers)
# Creates jobserver with automatically detected number of workers
job_server = pp.Server(ppservers=ppservers)
print "Starting pp with", job_server.get_ncpus(), "workers"
start_time = time.time()
# Since jobs are not equal in the execution time, division of the problem
# into a 100 of small subproblems leads to a better load balancing
parts = 100
step = (end - start) / parts + 1
jobs = []
lines = {}
for index in xrange(parts):
starti = start + index * step
endi = min(start + (index + 1) * step, end)
jobs.append(job_server.submit(calc_dis, (lines, arr, starti, endi, end), (), ("math", "numpy",)))
job_server.print_stats()
[job() for job in jobs]
job_server.print_stats()
end_time = time.time()
print end_time - start_time
python并行计算
最新推荐文章于 2024-06-01 22:12:02 发布