The Gurobi module adds the Gurobi Matlab connector to the Matlab path via the MATLABPATH environment variable. You should find that the gurobi command is available within Matlab. There are several examples of using the Matlab connector in the Gurobi $GUROBI_HOME/examples/matlab directory.
Running Gurobi from Matlab interactively
As an example, to run the diet.m example, you can make a copy in your directory, then run it from inside Matlab.
$ module load gurobi matlab $ cp $GUROBI_HOME/examples/matlab/diet.m ./ $ matlab -nodisplay Copyright 1984-2015 The MathWorks, Inc. [ . . . .] >> diet Optimize a model with 4 rows, 13 columns and 40 nonzeros Coefficient statistics: Matrix range [1e+00, 2e+03] Objective range [9e-01, 3e+00] Bounds range [6e+01, 2e+03] RHS range [0e+00, 0e+00] Presolve removed 0 rows and 3 columns Presolve time: 0.03s Presolved: 4 rows, 10 columns, 37 nonzeros Iteration Objective Primal Inf. Dual Inf. Time 0 0.0000000e+00 4.601562e+00 0.000000e+00 0s 4 1.1828861e+01 0.000000e+00 0.000000e+00 0s Solved in 4 iterations and 0.03 seconds Optimal objective 1.182886111e+01 Cost: 11.828861 Buy: hamburger 0.604514 milk 6.97014 ice cream 2.59132 Nutrition: calories 1800 protein 91 fat 59.0559 sodium 1779 Adding constraint at most 6 servings of dairy Optimize a model with 5 rows, 13 columns and 42 nonzeros Coefficient statistics: Matrix range [1e+00, 2e+03] Objective range [9e-01, 3e+00] Bounds range [6e+01, 2e+03] RHS range [6e+00, 6e+00] Presolve removed 0 rows and 3 columns Presolve time: 0.00s Presolved: 5 rows, 10 columns, 39 nonzeros Iteration Objective Primal Inf. Dual Inf. Time 0 0.0000000e+00 4.601562e+00 0.000000e+00 0s Solved in 3 iterations and 0.00 seconds Infeasible model No solution
Running Gurobi from Matlab in batch
If you wish to run the example in batch mode, you need to edit the copy of diet.m and add a line to the end with the exit command, or Matlab will run the example and return to the Matlab >> prompt. Once you have done that,
$ matlab -nodisplay -r diet
will run the example.
Running Gurobi from Matlab from a PBS script
To run Gurobi from within Matlab using a PBS script you must also modify the diet.m file to include an exit command, as above, otherwise Matlab will remain at the prompt until the requested walltime has elapsed rather than exiting, hence also exiting the PBS job, when the example has finished.
Here is an example PBS script that can be used as a template.
#### PBS preamble #PBS -N PBS_test_script #PBS -M email@example.com #PBS -m abe #PBS -A example_flux #PBS -l qos=flux #PBS -q flux #PBS -l nodes=1:ppn=1,pmem=1gb #PBS -l walltime=15:00 #PBS -j oe #PBS -V #### End PBS preamble if [ -s "$PBS_NODEFILE" ] ; then echo "Running on these nodes" uniq -c $PBS_NODEFILE fi if [ -d "$PBS_O_WORKDIR" ] ; then cd $PBS_O_WORKDIR echo "Running from PBS_O_WORKDIR: $(pwd)" else echo "Running from $(pwd)" fi # Put your job commands after this line matlab -nodisplay -r diet