Parallel for loops on Pull Point (Pull) / Curve Closest Point

Hi all,

Has anyone tried running the pull point or curve closest point method through parallel for loops/multi threading to increase performance? the native components in gh start to get quite slow once the amount of points and curves increase.

Thanks,

Tim

You are in the Python bangwagon?
PS: Post something to start talking

actually tried it once in c# / vs improving the evaluation component through System.Threading.Tasks.Parallel.For() but am not very familiar with it, so am seeking for advice, and thought someone on here probably has done it already.
Attached a comparison - the ‘gh_test_1’ component implemented with the parallel method.
parallel_eval_1.gh (22.0 KB)

Try (one crv VS a zillion pts, other examples to follow):

static void ClosestPoints(ref List closestPts, Curve crv, List pts){
int degreeOfParallelism = Environment.ProcessorCount;
List closest = new List();
System.Threading.Tasks.Parallel.For(0, degreeOfParallelism, workerId =>
{
var max = pts.Count * (workerId + 1) / degreeOfParallelism;
for (int i = pts.Count * workerId / degreeOfParallelism; i < max; i++){
double t; crv.ClosestPoint(pts[i], out t);
Point3d p = crv.PointAt(t);
closest.Add§;
}
}
);
closestPts = closest;
}

BTW: no idea why the List is saved as above:

Get this as well

multithreading_examples_V2.gh (124.8 KB)

1 Like

Hi Peter,

Thanks a lot for the code!
I remember that apparently multi-threading will only work in compiled components?
See last paragraph of the first section:

I gave your component a try and compare it with native components (please find attached) -
it doesn’t seem to really be faster? Am I not understanding something correctly?
multithreading_examples_V2_test.gh (14.4 KB)

Well … I do hope that you have noticed the “Nirvana?” title on top of all the examples. The question mark makes all the difference he he.

Anyway read first what the Master has to say and we talk later:

http://www.albahari.com/threading/

And given the opportunity get this as well that is using the .AsParallel AND the .AsPointless [(C), ™, US Patent pending] things that … er … hmm … prove that hope dies last (it should die first).

Pop_pts_MinMax_PLINQ_V1A.gh (127.0 KB)

1 Like

BTW: Added the hope option (kinda the 3rd marriage) …

multithreading_examples_V2A.gh (127.5 KB)

…it makes some difference (on average: half the time ) … but in real-life and for real-things and for real projects (paid with real money [I do hope])… well … you get the gist I assume.

Get this as well:

Parallel_12A_V1.gh (127.3 KB)

Moral: May the Force (the Dark option) be with you.

2 Likes

And by assuming that you have done your homework by now > see this as well (includes a big sardine challenge).

Parallel_47B_V1.gh (120.0 KB)