Is OSQP multi-thread safe?

382 views
Skip to first unread message

Minchen

unread,
Nov 18, 2018, 12:30:25 AM11/18/18
to OSQP
Dear Author,

I'm using OSQP for my research and it works pretty well! But I have a question on multi-thread OSQP:
say I have n threads, each thread has its own OSQPSettings, OSQPData, and OSQPWorkspace, and each thread will call osqp_cleanup(work), work = osqp_setup(data, settings), and osqp_solve(work) multiple times since I'm doing SQP with number of constraints changing. Will the call on one thread affect other thread?
I'm asking this question because right now I'm getting different results when using single thread or multi-thread as described.
Looking forward for your reply!

Thanks!
Minchen

Bartolomeo Stellato

unread,
Nov 18, 2018, 12:27:46 PM11/18/18
to jermain...@gmail.com, os...@googlegroups.com
Hi Minchen,

Glad OSQP is useful to you! Most of the OSQP code is single-threaded at the moment. The only part that can be multi-threaded is when you use the MKL library as a linear system solver. MKL is thread-safe so there is no problem in using it with multiple OSQP instances.

I am surprised you are getting different results with multiple OSQP instances in parallel. Which language are you using? Is it possible for you to send us a minimal working example that reproduces the issue?

Bartolomeo


--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osqp/89b64736-f53d-492c-be15-2ad3262c3cee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Minchen Li

unread,
Nov 18, 2018, 11:53:45 PM11/18/18
to bartolome...@gmail.com, os...@googlegroups.com
Hi Bartolomeo,

Thanks a lot for your quick reply! I'm using C++, and unfortunately the code is very complicated and hard to extract. I'm also checking whether I made any mistakes on shared variables.
Here I attached a wrapper class I wrote for the OSQP solver, and after creating several instances of it, I keep calling setup() and solve() again and again with potentially different number of constraints on each instance.
I will let you know if I have any updates. I would also be really appreciated if you have time to have a look at my wrapper class and correct my misunderstandings of any.

Thanks!
Minchen
OSQP.h
Reply all
Reply to author
Forward
0 new messages