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.



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. (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);
closestPts = closest;

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

Get this as well (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? (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:

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). (127.0 KB)

1 Like

BTW: Added the hope option (kinda the 3rd marriage) … (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: (127.3 KB)

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


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