Multithreading computationally heavy tasks in HalconDotNet

258 Views Asked by At

For a project with a very large database I am using the following two procedures thousands of times in a loop:

select_points_object_model_3d()
render_object_model_3d()

This takes hours and hours for every test as it is using only 1/16 cores. Now I was wondering: Is there a way to run multiple HDev engines in different threads all executing said procedures?

2

There are 2 best solutions below

0
Malinko On BEST ANSWER

I forgot to come back to this when I found a solution. For the next one who is stuck on this. Using taskList[i] = new Task<>(() => {"task code"}); I was able to run 450+ tasks that use HOP.SelectPointsObjectModel3d() and HOP.RenderObjectModel3d() consecutively completely utilizing all my cores. I didn't need multiple engines or anything like that.

1
ehlus On

You can try to work with halcon multithreading operators.

Infinitely running:

par_start<Thread1>: procedure(...)

Wait for threads to finish:

par_start <Thread1> : process (...)
par_start <Thread2> : process (...)
par_join ([Thread1, Thread2])

See: https://www.mvtec.com/doc/halcon/12/en/par_join.html