run a function in another processor in python

Discussion in 'Python' started by Astan Chee, Dec 9, 2010.

  1. Astan Chee

    Astan Chee Guest

    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
     
    Astan Chee, Dec 9, 2010
    #1
    1. Advertising

  2. Astan Chee

    News123 Guest

    On 12/09/2010 10:54 AM, Astan Chee wrote:
    > 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
     
    News123, Dec 13, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christoph
    Replies:
    1
    Views:
    274
    Peter van Merkerk
    Dec 1, 2003
  2. brahatha
    Replies:
    1
    Views:
    685
  3. Replies:
    3
    Views:
    371
    Gabriel Genellina
    Jun 23, 2007
  4. Astan Chee
    Replies:
    4
    Views:
    491
    Peter Otten
    Dec 11, 2010
  5. stevetuckner
    Replies:
    3
    Views:
    218
    stevetuckner
    Sep 21, 2005
Loading...

Share This Page