Disabling threading in CPLEX

Since version 12.2, CPlex defaults to multithreading its executables.

This is a problem for several reasons and multithreading should be disabled in almost all cases. Not only does Condor handle single threaded jobs much better, but they will usually produce better performance.

We've modified the default environment in several places but it doesn't seem to work consistently. Thus users need to manually add a line to their C/C++ programs before compilation to turn off threading.

The C function call to disable threading should be put at the beginning of main():

CPXsetintparam(env, CPXPARAM_Threads, 1);

The C++ call to disable threading (assuming your IloCplex object is called 'cplex'):


In an AMPL batch file the command to turn off multithreading is:

option cplex_options 'threads=1';

Ampl, Cplex and Condor

An example of how to use cplex with ampl in a condor job can be found here:


It includes a sample model and data file as well as the necessary ampl run script and condor cmd files.

Copy the "ampl_cplex" folder to your home directory but before submitting to condor make sure to edit the .cmd file and replace the "username" in the log and notify_user entries with your login name.

Location of example CPLEX Code

An example scripts are located here :


This directory includes a sample data file, source code and makefile necessary run test code

Copy source code, data files and makefile to your home directory. Modify makefile to run your choosen script

Example CPLEX Makefile

This example makefile is for a C program :

SYSTEM     = x86-64_linux
LIBFORMAT  = static_pic

# When you adapt this makefile to compile your CPLEX programs
# please copy this makefile and set CPLEXDIR and CONCERTDIR to
# the directories where CPLEX and CONCERT are installed.

CPLEXDIR      = /opt/cplex/latest/cplex
CONCERTDIR    = /opt/cplex/latest/concert

# ---------------------------------------------------------------------
# Compiler selection 
# ---------------------------------------------------------------------

CC  = gcc -O0

# ---------------------------------------------------------------------
# Compiler options 
# ---------------------------------------------------------------------

COPT  = -m64 -fPIC -fno-strict-aliasing

# ---------------------------------------------------------------------
# Link options and libraries
# ---------------------------------------------------------------------

CPLEXJARDIR   = $(CPLEXDIR)/lib/cplex.jar

# For dynamic linking
CPLEXLIB      = cplex$(dynamic:yes=1290)
run           = $(dynamic:yes=LD_LIBRARY_PATH=$(CPLEXBINDIR))

CLNFLAGS  = -l$(CPLEXLIB) -lm -lpthread -ldl

        make all_c

execute: all
        make execute_c



#  make all      : to compile the examples. 
#  make execute  : to compile and execute the examples.

all_c: lpex3

execute_c: lpex3
        $(run) ./lpex3
        # ------------------------------------------------------------

clean :
        /bin/rm -rf *.o *~ *.class
        /bin/rm -rf lpex3
        /bin/rm -rf *.mps *.ord *.sos *.lp *.sav *.net *.msg *.log *.clp

# ------------------------------------------------------------
# The examples

lpex3: lpex3.o
        $(CC) $(CFLAGS) $(CLNDIRS) -o lpex3 lpex3.o $(CLNFLAGS)
lpex3.o: lpex3.c
        $(CC) -c $(CFLAGS) lpex3.c -o lpex3.o

# Local Variables:
# mode: makefile
# End:

Modify the makefile located in "/opt/cplex/latest/cplex/examples/x86-64_linux/static_pic/Makefile"