Speeding up parallel calculations of intersections (Rhinocommon)?

I have a large array of curves and a small array of surfaces, and I am finding the intersection between each curve and each surface. I need to speed this operation up.

I’ve adjusted the tolerance variable to be as forgiving as I can accommodate, which helped somewhat.

I need to parallel-ize. Can the rhinocommon intersection calculations be used in a multi-threaded manner? Is this something I can accelerate by offloading to GPU via CUDA or OpenCL?

Thanks in advance,


You can parallelize in in C# using the Task Parallel Library (TPL). I am using it to do a similar intersection problem - a couple of BREPs with a list of planes.

Basically, substitute a for loop with Parallel.For and this speeds things up. But, before doing an “expensive” CurveSurface intersection, why not do a “cheaper” bounding box intersection test. If the bounding boxes of the curve and the surface being intersected are disjoint, the intersection does not need to be computed.

Thanks for the suggestions, I will try them :smile:

I’m guessing that offloading to a GPU isn’t feasible then?

Careful here - the intersection code in Rhino is not thread safe. If you start calling the intersectors in parallel, you may get garbage results or crashes.

This was over a year ago, while RhinoCommon was presumably not complete, but seemed to suggest that this should be thread-safe.


Is this no longer true? Can someone clarify?

Um… I don’t think that is true Brian.

I would use Menno’s suggestion of a parallel for loop using the task parallel library

One thing that you DO need to be careful about is working with the Rhino document as that is not thread safe. Make all of your intersection calculations in a parallel for loop and collect your results. Once the loop is complete, you are back on the main thread of execution and you can work with the document (things like add points where the intersections occur)

Ok thanks.

The only thing I’m still unclear about is GPU offloading. If code is thread-safe does it qualify for this? Or are there more stringent requirements? I’m assuming no one knows, and I’m going to continue researching. But please, stop me if you know better :wink:

GPU offloading doesn’t really make much sense in the context of this question. The intersection functions in core Rhino are written to run on the CPU(s). Special code would need to be written to have these functions work on the GPU(s).