Closed julibeg closed 4 years ago
As a workaround I've now set the threads by adding self.problem.parameters.threads.set(5)
to the end of the __init__()
method of the Model
class in optlang's cplex_interface.py
Hi @zeawoas, and thank you for pointing this out.
I don't think optlang allows this explicitly through their Configuration object. For the time being I think I will add a n_threads parameter to the KShortestEnumerator constructor as well as an optional parameter in the higher level KShortestAlgorithm class.
The threads will then be set upon instantiating the algorithm classes by directly setting the solver parameters within the interfaces.
this would do nicely, thanks!
I just implemented something to address this so that it works in the following ways:
When using the KShortestEFMAlgorithm class:
config = KShortestProperties()
config[K_SHORTEST_MPROPERTY_METHOD] = K_SHORTEST_METHOD_ITERATE
config[K_SHORTEST_OPROPERTY_MAXSOLUTIONS] = 9
config[K_SHORTEST_OPROPERTY_N_THREADS] = 5 #threads go here!
`
With the higher-level wrapper:
algorithm = KShortestMCSEnumeratorWrapper(model=model, ... , n_threads=4) #threads go here!
Edit: Might merge this today and release as 0.1.4
I have tried to limit the number of threads used by CPLEX via cobamp with various environment variables (e.g. OMP_NUM_THREADS and a few CPLEX-specific ones), but none of these seem to work. Browsing through the documentation of cobamp as well as optlang didn't reveal how to specify the maximum number of threads/cores either. Is there a way of setting the number of threads used? Apologies, if this is a no-brainer, but I have never used CPLEX or code relying on optlang before.