CPLEX memory usage for MIPs

Xavier Nodet
5 min readFeb 26, 2021

We’ve seen in a prior post how to deal with memory when solving an LP.

This also applies for MIPs until the solve of the root relaxation. If you have a MIP model such that you need to reduce the amount of memory used by CPLEX and no or very few nodes have been explored yet, please turn to that post.

There are also many MIP models that are not that big in terms of the matrix size, but still need large amounts of memory. As an example for this post, I selected a very small model (1721 variables and 1632 constraints) for which CPLEX generates tons of nodes, and this can consume huge amounts of RAM. We’ll see how simple it is to avoid reaching an out-of-memory for such models.

RAM usage during tree exploration

After about 40 seconds of solving this model, CPLEX generated 50000 nodes. Here’s what the log looks like:

At this point, the maximum amount of physical RAM that the CPLEX process used (a.k.a MaxRSS) is 420 MB, of which CPLEX tells us that 163 MB are used to store the open nodes in the tree. So we can approximate the ‘core’ RAM size for this model to be around 250 MB.

Let’s see how the search evolves:

After 200.000 nodes have been explored, the size of the tree is close to 2 GB, and MaxRSS is 3.0 GB

At this point, the tree grew over 2 GB, which is the default value for the workmem parameter. For a MIP, this parameter governs the size of the ‘live’ tree. That is, the tree as CPLEX internally creates it, without any post-processing.

When the size of the tree reaches the value specified by workmem, CPLEX starts to apply a different strategy to store it. This strategy is controlled by the mip.strategy.file parameter:

  • 0: No node file
  • 1: Node file in memory and compressed; default
  • 2: Node file on disk
  • 3: Node file on disk and compressed

The default value is 1, and CPLEX therefore keeps the tree in memory. It tells us so with this message: Nodefile size = 417.85 MB (188.37 MB after compression). So CPLEX started to move some nodes away from the ‘live’ tree, and stored them after compression in the ‘nodefile’. We just have to keep in mind that, by default, this ‘nodefile’ is stored in memory, beyond the workmem limit.

As the search continues, the RAM usage of CPLEX keeps growing, but at a smaller rate. After 350.000 nodes have been explored, we have:

The tree reaches a total size of 3.2 GB, of which 2 GB are ‘live’, and 1.2 GB have been compressed down to 520 MB. The MaxRSS went from around 3.0 GB (when the working memory was almost full) to 3.5 GB, a growth of only 500 MB, despite the tree growing by 1.2 GB. Waiting further, we can confirm that the RAM usage grows with the size of the compressed tree. As a matter of fact, when we have

the MaxRSS is 4.0 GB.

Storing the tree on disk

This will continue until the search is over and the whole tree has been explored, or we reach an out-of-memory condition. Depending on your Operating System and its configuration, this can lead to two different outcomes. The best one is that at some point, when CPLEX wants to allocate more memory, the OS will deny this allocation. CPLEX will then graciously terminate the search with an OOM status.

It may also happen that the Operating System is more ‘optimistic’, and it assumes that processes won’t necessarily actually use the memory that they request. Such OSes tend to always grant the memory allocation requests done by the programs, but may kill kill the CPLEX process with no warning. In this case, the process exits with an error code 137, in a not so nice way.

To prevent either case, you can switch to using a nodefile on disk, with values 2 or 3 of the mip.strategy.file parameter. This will be slower than using RAM, but not necessarily by much. Here's what CPLEX displays in the log:

MaxRSS is 2.9 GB, as if the tree didn’t grow after reaching 2 GB. Conversely, if we limit the workmem to 1 GB with the commandset workmem 1024 in the Interactive, we get the following:

and the MaxRSS at this point is 1.5 GB.

Conclusion

The take away from all this is that, if your model produces many nodes and CPLEX uses too much memory, use set mip strategy file 3. You may also set workmem to an appropriate value depending on the amount of RAM you want CPLEX to consume, and the amount of RAM that has already been used at the start of the tree exploration.

--

--