Skip to main content

GRBaddconstr (or other) permissible inside of #pragma omp parallel for in C?

Answered

Comments

3 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Thomas,

    You cannot parallelize the calls to addConstrs(). But you can parallelize the construction of the set of constraints that you add. For example, you could try building 8 different sets of constraints (expression objects, like LinExpr) using parallelism, and after they have all been constructed call addConstrs() 8 times in a sequential fashion. This might bring some speedup in case expensive look-ups or function evaluations are involved when creating the expressions.

    So you can construct your constraints in parallel - you just have to add them sequentially. 

    Best regards, 
    Jaromił

    0
  • Thomas Leveringhaus
    Gurobi-versary
    Collaborator
    Investigator

    Hi Jaromił,

    thanks for your reply.
    I already assumed that GRBaddconstr() isn't thread-safe.
    But as you said, that's not really a problem because I can create the arguments for the function call in parallel.

    With GRBaddconstrs() [or GRBXaddconstrs()] the adding of constraints isn't even sequential but in one step, or do these routines internally simply add the constraints sequentially?

    Best regards

    Thomas

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Thomas,

    With GRBaddconstrs() [or GRBXaddconstrs()] the adding of constraints isn't even sequential but in one step, or do these routines internally simply add the constraints sequentially?

    Internally these methods are "just" copying memory entries from user arrays into internal data structures.Technically, it is sequential, but still way faster than adding every constraint one by one, because big chunks of data are moved at once instead of in tiny pieces via addconstr().

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.