MATLAB with Gurobi

In order to use MATLAB with Gurobi, you need to load both a MATLAB module and a Gurobi module (with prerequisites).

This means you have to start MATLAB from a terminal.

Note

You can use MATLAB and Gurobi together either

  • by submitting a job to the batch system with the “batch” command inside MATLAB (GUI or shell)
  • by submitting a job to the batch system with a batch script
  • by creating a “parpool” with the Kebnekaise cluster

Loading the modules

  1. In a Linux terminal, check which MATLAB version you want:
    ml spider MATLAB
    
  2. Load the version you picked. In this example version 2023a
    module load MATLAB/2023a.Update4
    
  3. Find a compatible version of Gurobi (one that is compiled with the same GCC compiler version).
    ml av Gurobi
    
  4. Load one of them. Here version 11.0.1
    module load Gurobi/11.0.1 
    

Running jobs from inside MATLAB

Note

This assumes you have done the Configuration and setup for MATLAB

  1. Start MATLAB in the terminal where you loaded the modules. Here
    matlab -singleCompThread
    
    • This starts the MATLAB GUI. If you want to run in a shell, instead do this:
      matlab -singleCompThread -nodisplay -nosplash -nodesktop
      
  2. The following commands are done inside MATLAB
  3. If you have not added your job settings, do so now - follow the link and go to item 3 on that page.
  4. You can now start a MATLAB script or function with Gurobi commands in with
    myjob = c.batch(myFcn,numOutput ,{input1, input2, input3, ...},'Pool' ,nWorkers);
    
    where
    • myFcn is a command or serial MATLAB program. Preface with @ if a command.
    • numOutput is the number of output expected
    • {input1, input2, input3, ...} are the inputs
    • 'Pool' is the parallel pool
    • nWorkers are how many workers
  5. Remember that there needs 1 more core than nWorkers

More information