I'm solving a bunch of similar problems and I want to compare them. To do so, I need everything to run on one thread. Even by setting the number of threads to 1, the model still runs on 8 threads. Has anyone ever encountered this problem? and is there a way to fix it? (I'm using Cplex with python)

Thank you,


2 Answers 2


Try using context as explained here. An example of modeling with docplex (shown below) indicates that you can change the default setting for solver options in cplex using the following code:

context = Context.make_default_context()
context.cplex_parameters.threads = 1
model = Model(context=context

Alternatively the code can be as follow:

model = Model()
model.context.cplex_parameters.threads = 1

Or if you are using Pyomo the following solver option will be used:

mysolver = SolverFactory('CPLEX')
mysolver.options['threads'] = 1
  • 1
    $\begingroup$ Thank you for your help! $\endgroup$
    – Almufa
    Oct 2, 2020 at 12:50

let me change the zoo example for your need. (Number of threads)

from docplex.mp.model import Model

mdl = Model(name='buses')


nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)


print("threads = ",mdl.parameters.threads.get())

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)

which gives

threads =  1
nbBus40  =  6.0
nbBus30  =  2.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.