Run Gurobi on the Cluster - Batch Mode¶
- 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
- The command line tool,
- This guide will focus on the command line tool,
gurobi_cl, you can submit jobs in batch mode (can run without supervision)
- In the
PBSscript, load gurobi with
module load gurobi/8.1.0. You can use
module avail gurobito 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
.lpfiles. 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
You must set
Threads to the number of processors you requested in the
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 -l nodes=1:ppn=4 #PBS -l pmem=2gb #PBS -l walltime=10:00 #PBS -q iw-shared-6 #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
#PBSdirectives are standard, requesting just 10 minutes of walltime and 1 node with 4 cores. More on
#PBSdirectives can be found in the PBS guide
$PBS_O_WORKDIRis simply a variable that represents the directory you submit the PBS script from. Make sure the
.lpmodel you want to run (in this case,
coins.lp) is in the same directory you put the PBS script.
module load gurobi/8.1.0loads 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_clruns the gurobi command line tool.
ResultFileis an optional paramter, and prints the result of the optimization to a
.solfile. More info on paramters can be found in documentation here
- You must set
Threadsto the number of processors you requested in the top of the
Part 2: Submit Job and Check Status¶
- Make sure you're in the dir that contains the
- Submit as normal, with
qsub <pbs script name>. In this case
- 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
PBSscript, you should see all the generated files, including
cat coins.solor open the file in a text editor to take a look
coins.solshould 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.