Ask Your Question
2

passing multiple variables and @parallel

asked 2011-01-25 21:24:27 +0100

mhfrey gravatar image

updated 2011-01-25 21:29:49 +0100

The @parallel examples all show f(x).
Is it possible to use f(x,y,z) where x is the list to be iterated over?
Are there any examples of @parallel that do not use list?

edit retag flag offensive close merge delete

Comments

Can you post a sample code to explain what you are trying to do? The most natural solution would be to pass an array.

Shashank gravatar imageShashank ( 2011-01-25 21:34:22 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2011-06-09 06:39:51 +0100

niles gravatar image

updated 2011-06-10 14:37:11 +0100

Indeed, this is missing from the documentation, and I found it confusing. With some fiddling, I learned that @parallel will pass tuples as arguments:

@parallel
def func(n,color='red'):
    sleep(2)
    return [n^2,color]

L=[2,(4,'blue'),5,(6,'green'),7]
r = func(L)

The output is as expected:

for s in r:
    print "func(%s) = %s"%(s[0][0][0],s[1])

func((2,)) = [4, 'red']
func((4, 'blue')) = [16, 'blue']
func((5,)) = [25, 'red']
func((6, 'green')) = [36, 'green']
func((7,)) = [49, 'red']


UPDATE: Ok, I guess I have time to at least create the ticket ;) This is now ticket 11462!

edit flag offensive delete link more

Comments

So open a ticket for this doc patch! :) You will become the new @parallel expert :)

kcrisman gravatar imagekcrisman ( 2011-06-09 17:03:50 +0100 )edit

ha! Yes I'd like to, but I don't quite have time for it right now -- maybe in a month or so . . .

niles gravatar imageniles ( 2011-06-09 17:07:33 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-01-25 21:24:27 +0100

Seen: 572 times

Last updated: Jun 10 '11