Are Multi-threaded Scripts forbidden?

Are multi-threaded scripts forbidden? Can’t find anything in here:

That was a mistake, please make a small change to the script and resubmit

Ok, thanks. I just uploaded the definition again. Generally, does it make sense to go for multi-threaded custom scripts to speed things up? I.e. is the Grasshopper Definition on your servers able to use multiple threads?

The script has been confirmed.

Multithreading can be used, no problem, however whether it makes sense depends on your application and how well your tasks can be parallelized.

Some Grasshopper users on a Windows machine have gotten the best speed up by calling C++ code from Python in a custom block. Parallelism can work much better in C++ for some cases.

For details on how to create a C++ DLL with procedures callable from Python, search the Forum for
Step by step details for adding C++ DLL to a Python script with working example

Regards,
Terry

1 Like

Thanks @snabela.

I’ve run a few tests using the following definition. “MT?” switches from using the native solid difference method to a multithreaded solid difference C# script. This task makes sense to get parallelized as each big cube sits in its own branch has its own subtractors.


Shapediver_Multithreaded_Test [Jul-10 '21, 1334].gh (26.4 KB)

Running locally, the difference is significant:
With native solid difference, it takes 6,3 seconds to compute 80 cubes
Using the C# Multi-threaded component, it takes 3,2 seconds to compute 80 cubes

These computation times are measured by opening the models so the computation times for the script compilation are included.

It’s uploaded on Shapediver. Using the multi-threaded component doesn’t make a difference here. It always times out (exceeding 10 seconds) at around 80 cubes.
https://app.shapediver.com/m/shapediver-multithreaded-test-jul-10-21-1334

Doesn’t this mean that Grasshopper definitions can only run single-threaded on Shapediver? In this case, I can’t see a scenario where parallelizing would improve speed. Am I wrong?

Hi @Simon_Vorhammer, on the shared system your account is assigned to we are currently using t3.medium instances which have 2 CPUs. How many threads have you been using on your local machine?

We are running a separate system for testing of workloads which can be sped up using parallelization, eg structural computations using Karamba. On this system the instances offer 8 CPUs. It might make sense to test your model there.

Hi @snabela, 12 threads were used on my local machine. I recorded a video (on the phone - so as not to drain performance) showing the difference in CPU workloads. I first refreshed the solution three times using the multi-threaded method. It’s evident, that all cores are being used. I then switched to the single-threaded method where some CPUs are showing peaks. Am I right in assuming, that even if no multi-threaded components are used, at least two CPUs are always somewhat busy? Which in return would explain, that there is no difference between the single- and multi-threaded methods with my definition on the t3.medium system as parallelization only improves speeds if more than two cores are available?

How could my file get tested on your 8-core system?

Hi @Simon_Vorhammer,

the second CPU on the t3.medium might be idle or busy at the moment of your computation, essentially that’s left to chance.

Please get in touch with sales in order to have an account of yours assigned to the 8-core system for testing.

1 Like