CPLEX Guide

From Storrs HPC Wiki
Jump to: navigation, search

IBM CPLEX optimizer

Main website

Documentation for v12.6.1

Please note that you need to be in the cplex unix group to be able to run the software. Contact the help desk for access.

Loading the module

Find the available modules with:

module avail cplex

Run the command:

module load cplex/12.6.1

Interactive job

Start an interactive job with:

fisbatch --exclusive -n12

Then run cplex with:

cplex

You will see the command prompt:

Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 12.6.1.0
  with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
Copyright IBM Corp. 1988, 2014.  All Rights Reserved.

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX>

Run the example code from the IBM documentation:

CPLEX> enter example
Enter new problem ['end' on a separate line terminates]:
maximize  x1 + 2 x2 + 3 x3
subject to -x1 +  x2 + x3 <= 20
            x1 - 3 x2 + x3 <=30
bounds
0 <= x1 <= 40
0 <= x2
0 <= x3
end
CPLEX> optimize
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Presolve time =    0.00 sec. (0.00 ticks)

Iteration log . . .
Iteration:     1   Dual infeasibility =             0.000000
Iteration:     2   Dual objective     =           202.500000

Dual simplex - Optimal:  Objective =   2.0250000000e+002
Solution time =    0.01 sec.  Iterations = 2 (1)
Deterministic time = 0.00 ticks  (3.38 ticks/sec)

CPLEX> display solution variables x1-x3
Variable Name           Solution Value
x1                           40.000000
x2                           17.500000
x3                           42.500000
CPLEX> quit

Interactive GUI

To launch the CPLEX studio, first you must login using X. After you login to the cluster desktop with x2go, launch a terminal and run:

module load cplex/12.6.1
fisbatch --exclusive -n12

At the prompt, type:

oplide

Now you can edit and run your opl files.

Remote object for distributed parallel optimization in C or C++

The CPLEX API provides 4 means of communication between master and worker processes as explained in IBM's manual [1]: local, process, MPI and TCP/IP. Currently there is an issue with MPI, but in the meantime one can use the process library for multi-threading on a single machine.

To make your own software, you can start by modifying one of the existing example programs.

To gain file ownership and write permission, you need to copy the entire examples directory to e.g. your home directory.

cp -a /apps2/cplex/12.6.1/cplex/examples ~/
cd ~/examples/x86-64_linux/static_pic/

To load Open MPI modules

module load mpi/openmpi/1.10.1-gcc

In C: Let's try compiling and running the parmipopt.c multi-process example [2] as documented in IBM's manual:

fisbatch -N 1 -n 3
make -f Makefile.remote remote-run-parmipopt

In C++: Let's try compiling and running the iloparmipopt.cpp multi-process example [3] as documented in IBM's manual:

fisbatch -N 1 -n 3
make -f Makefile.remote remote-run-iloparmipopt

Because results will not all be displayed on the screen of PuTTY, it may be a good idea to write results into a file, and then read the file:

make -f Makefile.remote remote-run-iloparmipopt > abc
nano abc

The best way is to capture command output while also viewing it live

make -f Makefile.remote remote-run-iloparmipopt | tee abc2
nano abc2

To submit jobs, we need a submission script (slurm.sh):

#!/bin/bash
# set number of cores here
#SBATCH -n 48

make -f MakefileCpp.remote remote-run-iloparmipopt

To submit it:

sbatch slurm.sh # you can change the name to whatever you want.

The stdout and stderr will be in the file: slurm-$JOBID.out

Edit a makefile or C++ file

One IDE to see colorful makefiles is Eclipse. To launch the Eclipse, first you must login using X. After you login to the cluster desktop with x2go, launch a terminal and run:

module avail eclipse

You will see:

--------------------------------------------------- /apps2/Modules/3.2.6/modulefiles ---------------------------------------------------
eclipse/4.3.2-javaee eclipse/cpp-luna-SR2
module load eclipse/cpp-luna-SR2
fisbatch --exclusive -n12

At the prompt, type:

eclipse

Now you can edit and run your makefiles or C++ files.