Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Set number of threads through API

#1
I recently came across the code snippet below from the documentation here.

Code:
# How to change the number of threads using by the RoboDK application:
RDK.Command("Threads", "4")

I have a few questions:
1. What is the default number of threads used?
2. What are some examples of tasks that RoboDK can take advantage of parallel processing for?
3. I haven't touched this parameter before. Should I expect that changing the number of threads used may have a significant effect on the execution speed of my code?
#2
Regarding your questions:
  1. The default threads value is the number of threads that your CPU can process. I understand this is usually a number between 1 and 2 times the number of cores your CPU has.
  2. Threads are mostly used for collision checking. This includes detecting selected objects using the mouse cursor.
  3. I don't think you'll see a remarkable increase of performance by changing the number of threads used. Using CUDA cores requires a Nvidia graphics card can help under some circumstances. However, when it comes to collision checking, performance can usually be remarkably improved by simplifying the geometries. We recently released a new add-in that helps to simplify objects for collision checking:
    https://robodk.com/addin/com.robodk.app.simplifymesh
#3
Hi Albert, thanks for the additional info. This is great -- the advice for collision detection best-practices is extremely valuable and I think I'll get a huge boost from simplifying some overly-complicated mechanism models this way.

To put it more precisely, does this mean it's using the number of logical cores as opposed to the number of physical cores?

I have a setup where I launch N instances of RoboDK and use N threads to simultaneously check N situations where collisions might occur using robolink.Robolink.Collisions().
  1. Would you expect that this setup is faster or slower than RoboDK's built-in implementation of multithreaded collision-detection? That is, might it be faster to use a single instance of RoboDK and let RoboDK decide how to speed up the collision detection by using N threads? I imagine that a single RoboDK instance would have a lot of overhead starting N threads for just a single call to `RDK.Collisions()`.
  2. In my setup, to optimize performance, should I use `RDK.Command()` to restrict each of my N instances of RoboDK to use only `my_number_of_logical_cores / N` or will they play-nice together without manual intervention?
#4
That's correct. RoboDK uses the number of logical cores instead of the physical cores.

Running multiple instances of RoboDK can help speed things up but requires more programming on your end (for example, to split one task among different instances of the RoboDK API). In this case, letting each instance of RoboDK run multiple tasks in parallel may not help overall. However, each setup is different and the best way is to test it. It also depends if your computer is working on other things not related to RoboDK.

One instance of RoboDK may take some RAM but should not use CPU resources if you are not using it. Also, if you start RoboDK with the -NOUI option it will use less RAM as it skips all resources needed for display.

Regarding your last question (2): I'm not sure if changing the number of threads can help, each setup is unique. The best way is to test it. Having multiple threads should not create much overhead while it can help involve unused CPU resources to speed things up.
#5
Thank you, Albert!
#6
For those struggling with performance with collision detection, we added best practices in our documentation:
https://robodk.com/doc/en/Collision-Avoi...isionCheck
Please read the Forum Guidelines before posting!
Find useful information about RoboDK by visiting our Online Documentation.
  




Users browsing this thread:
1 Guest(s)