I am running an optimization model using the Python API of CPLEX, docplex.mp.
Right now it looks like this:
from docplex.mp.model import Model
import time
mdl = Model()
# variables, constraints and objective function here
mdl.context.cplex_parameters.threads = 5
mdl.parameters.timelimit.set(3600)
start = time.time()
sol = mdl.solve()
end = time.time()
cpu_time = sol.solve_details.time
print("Time directly from solver: ",cpu_time)
print("Elapsed time: ",end-start)
My goal is to obtain the CPU time, which, since I am using more than 1 thread, I believe it should be different from the elapsed time. However, the "print()" operations are returning the same value. How can I obtain the CPU time here instead of the elapsed time? For instance, with docplex.cp it is possible to change the "TimeMode" to "CPUTime", but it didn't work here.
The parameter ClockType
https://www.ibm.com/docs/en/icos/22.1.1?topic=optimizers-clock-settings-time-measurement
can be set this way:
model.parameters.clocktype = 1
to get CPU time reported. However, you cannot have both measurements unless you measure elapsed time yourself.