Updated 2021-05-17

Gurobi

Run Gurobi on the Cluster - Batch Mode

Overview

  • There are a couple of options for running Gurobi:
    • The command line tool, gurobi_cl (aka batch mode)
    • Gurobi interactive shell (extension of python shell)
    • As a python library
  • This guide will focus on the command line tool, gurobi_cl
  • Using gurobi_cl, you can submit jobs in batch mode (can run without supervision)

Tips

  • In the PBS script, load gurobi with module load gurobi/8.1.0. You can use module avail gurobi to see what versions of gurobi are available.
  • Gurobi_cl can take in many different models, with languages such as Java, C, C++, Matlab, R etc. Gurobi can also take in .lp files. For more information on what you can run with gurobi_cl, refer to the gurobi documentation
  • Important: In the line to run gurobi, gurobi_cl ResultFile=<filename>.sol Threads=4 <model_name>.lp

Warning

You must set Threads to the number of processors you requested in the #PBS directives.

Walkthrough: Run Gurobi on the Cluster

  • This walkthrough will use an example optimization problem straight from the gurobi documentation
  • Simply, the problem looks to maximize the total value of coins to mint given a limited amount of metal
  • Input model (from Gurobi Documentation): coins.lp
  • PBS Script: gurobi.pbs
  • You can transfer the files to your account on the cluster to follow along. The file transfer guide may be helpful.

Part 1: The PBS Script

#PBS -N gurobiTest
#PBS -A [Account] 
#PBS -l nodes=1:ppn=4
#PBS -l pmem=2gb
#PBS -l walltime=10:00
#PBS -q inferno
#PBS -j oe
#PBS -o gurobiTest.out

cd $PBS_O_WORKDIR
module load gurobi/8.1.0
gurobi_cl ResultFile=coins.sol Threads=4 coins.lp
  • The #PBS directives are standard, requesting just 10 minutes of walltime and 1 node with 4 cores. More on #PBS directives can be found in the PBS guide
  • $PBS_O_WORKDIR is simply a variable that represents the directory you submit the PBS script from. Make sure the .lp model you want to run (in this case, coins.lp) is in the same directory you put the PBS script.
  • module load gurobi/8.1.0 loads the 8.1.0 version of Gurobi. To see what Gurobi versions are available, run module avail gurobi, and load the one you want
  • gurobi_cl runs the gurobi command line tool. ResultFile is an optional paramter, and prints the result of the optimization to a .sol file. More info on paramters can be found in documentation here
  • You must set Threads to the number of processors you requested in the top of the #PBS directives.

Part 2: Submit Job and Check Status

  • Make sure you're in the dir that contains the PBS Script
  • Submit as normal, with qsub <pbs script name>. In this case qsub gurobi.pbs
  • Check job status with qstat -u <gtusername3> -n
  • You can delete the job with qdel 22182721 , replacing the number with the jobid returned after running qsub

Part 3: Collecting Results

  • In the directory where you submitted the PBS script, you should see all the generated files, including coins.sol, gurobi.log, and gurobiTest.out
  • Use cat coins.sol or open the file in a text editor to take a look
  • coins.sol should look like this:
# Objective value = 113.45
Pennies 0
Nickels 0
Dimes 2
Quarters 53
Dollars 100
Cu 999.8
Ni 46.9
Zi 50
Mn 30
  • The optimization problem has been solved, and the ideal solution is to mint 100 Dollar coins, 53 quarters, and 2 dimes.
  • After the result files are produced, you can move the files off the cluster, refer to the file transfer guide for help.
  • Congratulations! You successully ran the gurobi_cl tool on the cluster.