Parallel computing : too many values to unpack

Hi everyone, I need to speed up a code and am trying parallel computing to solve Mesh Plane intersections. Nevertheless I get the error “too many values to unpack” when using parallel. I fear the error pops out because my function has more than one arguement, and I´ve packed all inputs in a tuple to handle the parallel computing. The function works perfectly fine without parallel.

What am I doing wrong?

import Rhino.Geometry.Intersect as rgIntersect
from ghpythonlib import parallel

def MeshPlaneSections(args):
    # packing function arguments in a tuple to enable parallel computing
    meshes,plane = args
    
    result =[]
    for mesh in meshes:
        intersections = rgIntersect.Intersection.MeshPlane(mesh,plane)
        if intersections is not None:
            for poly in intersections:
                result.append(poly)
    return result

input = (M,P) #argument tuple

sections = MeshPlaneSections(input) #no parallel computing, working fine

#sections = parallel.run(MeshPlaneSections,input) #parallel computing, not working

Another question, another approach : would this code run faster in csharp instead of python ?

Thanks for the help!

So the doc says run() would execute the provided method (first argument) on each of the items in the provided list/collection (second argument). That means your script is actually going down each item of your tuple. All you have to do is to wrap your tuple in a collection so each tuple is treated as an item. Like so:

sections = parallel.run(MeshPlaneSections,[input,])

1 Like

thanks Will! it perfectly solved my code, which now runs as such

import Rhino.Geometry.Intersect as rgIntersect
from ghpythonlib import parallel

#https://discourse.mcneel.com/t/gh-python-intersect-list-of-surfaces-in-rhino-geometry/134676

def MeshPlaneSections(args):
    #packing function arguments in a tuple to enable parallel computing
    meshes,plane = args
    
    result =[]
    for mesh in meshes:
        intersections = rgIntersect.Intersection.MeshPlane(mesh,plane)
        if intersections is not None:
            for poly in intersections:
                result.append(poly)
    return result

input = [(M,P)] #argument tuple

sections = parallel.run(MeshPlaneSections,input)[0] #parallel computing

do you have any idea how can I try converting this into C#? I´m not familiar with this programming language at all, but it´d like to test id the code runs faster than with parallel computing in python…