Giter Site home page Giter Site logo

Comments (3)

jaeandersson avatar jaeandersson commented on June 19, 2024 1

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.

fabmene avatar fabmene commented on June 19, 2024

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 or MX 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 DMs 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 use Function::call(const std::vector<DM> &arg, std::vector<DM> &res, ...)
  • This way you can pre-allocate all DM for arg and res
    • 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.

fabmene avatar fabmene commented on June 19, 2024

Interesting, I didn't know you could avoid passing DMs altogether!

from casadi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.