Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Concurrent environments

One algorithmic option available in Gurobi is concurrent optimization, where multiple independent solves are performed in parallel and Gurobi takes care of collecting and combining the results. Concurrent optimization can be quite powerful; it is actually the default approach for solving linear programming models.

The power of concurrent optimization comes from the fact that different approaches to solving a model may have different performance characteristics, and performing them in parallel allows you to stop when the first one finishes. All of our concurrent schemes have default choices for determining the strategy that each independent solve uses. However, it is also possible for you to pick different strategies. This is done through concurrent environments. By creating two or more concurrent environments for a model, and setting parameters on these environments, you can control exactly what each concurrent solve does.

Concurrent environments are created via API routines (in `C`, `C++`, `Java`, `.NET`, or `Python`). You set parameters on these environments as you would with any other environment, but in this case they only affect one of the several independent solves.

To give a simple example, you could do the following:

    /* Create concurrent environments */
    GRBenv *env0 = GRBgetconcurrentenv(model, 0);
    GRBenv *env1 = GRBgetconcurrentenv(model, 1);

    /* Set parameters on concurrent environments
    (for ease of readability, errors are not checked here) */
    error = GRBsetintparam(env0, "MIPFocus", 1);
    error = GRBsetintparam(env1, "MIPFocus", 2);

    /* Perform concurrent optimization */
    error = GRBoptimize(model);

    // Create concurrent environments
    GRBenv env0 = model.getConcurrentEnv(0);
    GRBenv env1 = model.getConcurrentEnv(1);

    // Set parameters on concurrent environments
    env0.set("MIPFocus", 1);
    env1.set("MIPFocus", 2);

    // Perform concurrent optimization
    model.optimize();

    // Create concurrent environments
    GRBenv env0 = model.GetConcurrentEnv(0);
    GRBenv env1 = model.GetConcurrentEnv(1);

    // Set parameters on concurrent environments
    env0.Set("MIPFocus", 1);
    env1.Set("MIPFocus", 2);

    // Perform concurrent optimization
    model.Optimize();

    // Create concurrent environments
    GRBenv env0 = model.getConcurrentEnv(0);
    GRBenv env1 = model.getConcurrentEnv(1);

    // Set parameters on concurrent environments
    env0.set("MIPFocus", 1);
    env1.set("MIPFocus", 2);

    // Perform concurrent optimization
    model.optimize();

    # Create concurrent environments
    env0 = model.getConcurrentEnv(0)
    env1 = model.getConcurrentEnv(1)

    # Set parameters on concurrent environments
    env0.setParam('MIPFocus', 1)
    env1.setParam('MIPFocus', 2)

    # Perform concurrent optimization
    model.optimize()

    ' Create concurrent environments
    Dim env0 As GRBEnv = model.GetConcurrentEnv(0)
    Dim env1 As GRBEnv = model.GetConcurrentEnv(1)

    ' Set parameters on concurrent environments
    env0.Set("MIPFocus", 1)
    env1.Set("MIPFocus", 2)

    ' Perform concurrent optimization
    model.Optimize()

This would launch two concurrent solves on your model, one with the MIPFocus parameter set to 1 and the other with it set to 2.

Please note that parameter values are copied from the model when the concurrent environment is created. Therefore, changes to parameter values on the model have no effect on concurrent environments that have already been created unless parameter InheritParams is set to 1. This is a frequent source of confusion.

Users of our command-line interface can set concurrent optimization parameters with `.prm` files using the ConcurrentSettings parameter.

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support