Comments (3)
Iirc, Function::call(const std::vector<DM> &arg, std::vector<DM> &res, ...)
will not necessarily avoid the non-thread issues, for example if sparsity has to be projected. I think the easiest overload to use for thread safe function evaluation is arguments and results as std::map<std::string, std::vector< double >>
from casadi.
This issue is already some months old, so you probably moved ahead with this already. But after dealing with a very similar issue, here's what I can tell:
- Creating
DM
,SX
orMX
is not thread safe - Solvers may not be thread safe (IPOPT is, but even then the linear solver used by IPOPT might not be)
- Casadi function evaluations may create
DM
s behind the scenes if not set up exactly right.
The last point is the most tricky in my opinion, but this thread hints at it. The key takeaways:
Edit: Not the best approach. See comment below by @jaeandersson
- Don't use
Function::operator()
, but instead useFunction::call(const std::vector<DM> &arg, std::vector<DM> &res, ...)
- This way you can pre-allocate all
DM
forarg
andres
arg
must contain in this order:x0, p, lbx, ubx, lbg, ubg, lam_x0, lam_g0
res
must contain in this order:x, f, g, lam_x, lam_g, lam_p
and will contain the result. Fill with anything.- They must all be of the correct size for your problem. If they are not, they are getting resized, which is not threadsafe
This is just from my trial and error and I don't have a deep understanding of how casadi works under the hood, so take with a grain of salt.
from casadi.
Interesting, I didn't know you could avoid passing DM
s altogether!
from casadi.
Related Issues (20)
- Set bounds not constraint HOT 2
- The infeasible result is shown as βThe infeasible result is shown as abcβ in matlab, I can't find it in the help doc, I look forward to your help.
- NLP solver returning over-constrained warning and wrong results
- Change casadi_int by size_t (unsigned) when iterating vectors and strings
- Use `Fmu2::deserialize` only if compiled with `WITH_FMI2`
- Acessing the adjoint state HOT 3
- python kernel crash during integration
- Integrade NLPsolver in a class but outputs are all zeros
- Performance of FMU implementation HOT 1
- External function derivative detection in CasADi 3.6.x HOT 7
- qpsol creates multiple gurobi environment
- ipopt Nan detect for output jac_g_x
- 'C compiler cannot create executables' error when trying to compile HSL solver on Mac OS X HOT 5
- g and lam_g from nlpsol_out does not return any values HOT 4
- Too much pagefile HOT 1
- No parallelization when NLP (using mumps) is converted to function object and map is used with threads
- python crash when funtion from opti (sqpmethod) is evaluated in parallel HOT 2
- Add option to check if the number and names of function inputs is correct even when using a map
- stdout handling for external
- codegen C API finenuning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from casadi.