Using an API to Create a Compute Server Job

As was noted earlier, a Remote Services client program will always need to be told how to reach the Remote Services cluster. This can be done in two ways. The first is through a license file. This approach is described in an earlier discussion. It requires no changes to the application program itself. The same program can perform optimization locally or remotely, depending on the settings in the license file.

Your second option for specifying the desired Compute Servers is through API calls. You would first construct an empty environment (using GRBemptyenv in C or the appropriate GRBEnv constructor in the object-oriented interfaces), then set the appropriate parameters on this environment (typically ComputeServer and ServerPassword), and then start the empty environment (using GRBstartenv in C or env.start() in the object-oriented interfaces). In Python, you can directly give the appropriate parameters to the environment when creating it.

Once a model is solved and you have retrieved the results from it, we recommend you dispose of it immediately. If you don’t need the environment for another model, dispose of the environment as well, to release the remote job. The following example shows how to offload the optimization computation to a Compute Server named server1 in various APIs, with proper resource management.

     GRBenv   *env   = NULL;
     GRBmodel *model = NULL;
     int error = 0;

     error = GRBemptyenv(&env);
     if (error) goto QUIT;
     error = GRBsetstrparam(env, GRB_STR_PAR_COMPUTESERVER, "server1:61000");
     if (error) goto QUIT;
     error = GRBsetstrparam(env, GRB_STR_PAR_SERVERPASSWORD, "passwd");
     if (error) goto QUIT;
     error = GRBstartenv(env);
     if (error) goto QUIT;

     error = GRBreadmodel(env, "misc07.mps", &model);
     if (error) goto QUIT;
     error = GRBoptimize(model);
     if (error) goto QUIT;

     /* Extract the solution */
     /* ... */

QUIT:
     GRBfreemodel(model);
     GRBfreeenv(env);

     /* return error; */

We refer you to the Gurobi Reference Manual for details on these routines.