run a function in another processor in python

A

Astan Chee

Hi,
I've got a python script that calls a function many times with various
arguments and returns a result. What I'm trying to do is run this
function each on different processors and compile the result at the
end based on the function result. The script looks something like
this:


import time

def functionTester(num):
return ((num+2)/(num-2))**2

num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91]

max_result = 0

start = time.time()

for n in num_args:
result = functionTester(n)
if result > max_result:
max_result = result

print "Result " + str(max_result)
end = time.time()
elapsed= end - start
print "Took", elapsed, "seconds to execute"


What I'm trying to do is run each function on a processor and when its
done, move on to the next function-argument specifically on windows 7
x64 using python 2.6. How do I do this?
Thanks for any help
 
N

News123

Hi,
I've got a python script that calls a function many times with various
arguments and returns a result. What I'm trying to do is run this
function each on different processors and compile the result at the
end based on the function result. The script looks something like
this:
You could look at the multiprocessing module of
pythonhttp://docs.python.org/library/multiprocessing.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top