Use multi threading with HiGHS solver in MathOpt

527 views
Skip to first unread message

Shubham Chaudhary

unread,
Jul 28, 2024, 1:45:49 AM7/28/24
to or-tools-discuss
Hi,

I am trying to use multi threading with HiGHS solver in OR-Tools MathOpt:

params = mathopt.SolveParameters(enable_output = True, threads = 8, random_seed = 1234)
result = mathopt.solve(model, mathopt.SolverType.HIGHS, params = params)

The HiGHS solver is working fine without multithreading. But, I am getting the below error when I am trying to use multithreading:
RuntimeError: threads not supported for HiGHS solver, this must be set using globals, see HiGHS documentation [INVALID_ARGUMENT]

I don't know how to set it using globals. Can anyone please help?

Ross Anderson

unread,
Jul 28, 2024, 2:21:15 PM7/28/24
to or-tools-discuss
I have not looked at this code for > 1 year, so I do not remember exactly what needs to be done. Also, we are stuck on HiGHS 1.4 internally, but or-tools uses HiGHS 1.7. What I am saying is based on 1.4, I have not looked at the most recent version of the code.

I think the function you want to call is

highs::parallel::inititalize_scheduler(num_threads)

defined in HighsParallel.h from the Highs source. I am actually not sure if this is enough, you may also need to set the HiGHS specific parameter for threads (see here:


to set it). I would recommend trying to just call this function first and seeing from the logs/running time if it has any measurable effect. However, if you are doing this from python, it may not be so easy to do.

My understanding, from looking at the HiGHS code, is that there is a globally shared HighsTaskExecutor for all solves/solvers with Highs that is initialized once. If you call solve with Highs and a certain number of threads and this is not set, they set it for you on the first solve, but AFAICT it cannot be changed afterwards. Or maybe there is some issue if you have mulitple solves running concurrently that want a different number of threads each. I do not fully remember the details.

Some of these issues may have fixed in the more recent versions of HiGHS, see https://github.com/ERGO-Code/HiGHS/issues/506. I am not sure if anyone from the HiGHS team is on this list, perhaps they can comment further.

Also, not sure exactly what you are trying to do (LP/MIP etc), but in many cases you may not get much out giving HiGHS more threads, see: https://ergo-code.github.io/HiGHS/dev/parallel/#:~:text=By%20default%2C%20when%20running%20in,value%20of%20the%20threads%20option.

Reply all
Reply to author
Forward
0 new messages