Grasshopper

algorithmic modeling for Rhino

Help passing multiple arguments into grasshopper python parallel.run

I am having trouble with the new grasshopper parallel module when passing into it more than one argument.  In my example I am passing in two arguments, but when I retrieve it within the offsetSrf() function, there is only one argument available.  Does anyone know what I am doing wrong?  

Code:


def offsetSrf(args):
    print args
    cur, surf = args #unpack input
    cur = rs.coercecurve(cur)
    result = ghcomp.OffsetonSrf(cur, d, surf)
    return result

if parallel:
    args = (c, s)
    print args
    print ("***************************")
    slices = ghpythonlib.parallel.run(offsetSrf, args, True)

Views: 1911

Attachments:

Replies to This Discussion

Hi Jack,

The way parallel.run function works is that it takes a list of items, and then picks each item in that list and supplies the specified function with that item.
In your case (assuming the "c" and "s" input plugs are correctly set as lists) this is what it gets - a tuple of lists:

( [crv1,crv2,crv3,crv4], [srf1,srf2,srf3,srf4] )

The two items that parallel.run will take are:
[crv1,crv2,crv3,crv4] and [srf1,srf2,srf3,srf4].
And it will try to unpack them one by one, in each iteration:
cur, surf = [crv1,crv2,crv3,crv4]
cur, surf = [srf1,srf2,srf3,srf4]
Thus the error message: "too many values to unpack"

So just supply a list of lists, or list of tuples to make it work:

if parallel:

    args = [[c[i],s[i]] for i in range(len(c))]

Please attach your files next time.

Thank you for your help!  Changing the args = line fixed the problem.  Unfortunately the python component runs just slightly slower than the grasshopper component.  Is offset curve on surface just not a procedure that works well in parallel?

Attachments:

The node-in-code feature currently experiences some speed slowdowns. Looks like Steve and Giulio have found solution for this, or might even incorporate it in the next release of ghPython. Until then, using rhinocommon methods would be better.

Have in mind that each unecessary statement and line, adds a few milliseconds. I commented out all the redundant ones.

I am using an old AMD Sempron 3100 1.8Ghz, but still had a bit of speed increase in comparion with previous version. Your newer processor may have even more success.

Attachments:

hi djordje, is it possible do the same thing with a recursive function with more than 1 variable?

Hi GM,
I am not sure if it is or not.
But recursive solution in python would be slower than iterative one.

yes, of course. I'll try to apply the parallel.run function for each process into the recursion. hope it can improve the esecution velocity (actually really slow).

thanks anyway!

GM

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service