For more than 15 years, HALCON has parallelised operators internally to take advantage of multiple CPU cores. This is done transparently so no source code modification is required depending on whether you want to use one, two, or multiple threads in your application. This is also referred to as Automatic Operator Parallelisation (AOP).
By default, the number of threads HALCON creates is equal to the number of logical cores on the system. For a quad-core CPU with hyperthreading, for example, this would be 8. It might be desirable, however, to restrict the number of cores to ensure that enough system horsepower remains available for other tasks. The number of cores can be set with set_system, e.g.:
set_system(‘thread_num, 4)
Another point to consider is whether you want HALCON to be in charge of maximizing CPU utilisation or to take on that task yourself. For single camera applications it is usually best to just use the AOP. For multi-camera applications, however, you might get better performance if you create one application thread for each camera. In general the less amount of shared resources there are and the less synchronisation there needs to be between threads, the more effectively the CPU resources will be utilised.
Automatic Operator Parallelisation… Multiple User Threads?
When you do create several user threads, you should also restrict the number of threads HALCON uses for the AOP. As a rule of thumb, you will get the best performance if the total number of threads equals the number of logical cores. For a 2 camera application running on 8 cores, for example, you would create 2 application threads and limit the number of threads HALCON uses for the AOP to 4 for each thread:
Thread 1:
set_system(‘tsp_thread_num’, 4)
Thread 2:
set_system(‘tsp_thread_num’, 4)
The ‘tsp_’ prefix indicates that the setting applies to the calling thread only. The assumption here is that both threads are CPU intensive and take a similar amount of computing horsepower. Access to shared resources, or I/O that causes a thread to idle, may also change the picture.
Find out more about HALCON 12