Solver Foundation optimization library

Microsoft’s Solver Foundation is a numerical optimization library capable of solving problems involving millions of variables and millions of constraints. When I listened Scott Hanselman interview Nathan Brixius from Microsoft’s Solver Foundation team, I expected Brixius to say that Solver Foundation was written in C++ at its core and had a thin C# veneer to make it callable from .NET applications. Instead, he said that Solver Foundation is entirely written in managed code.

Even in heavy-duty numerical code the bottlenecks may not be numerical. The inner loops of the software would execute faster if they were written in C++, but Solver Foundation solves optimization problems about as quickly as other packages written in lower-level languages.

6 thoughts on “Solver Foundation optimization library

  1. Why do you assume that C# is necessarily slower than C++?

    Yes, Fortran and C (well written C) are faster than both C++ and Java (and C#)… but Java can very often match or even surpass C++.

    I still write C++ because

    (1) like it or not, garbage collection can be wasteful memory-wise, so for dealing with large in-memory data structures, you are better off in C++ than in Java;

    (2) intensive I/O is can awkward in Java.

    But for multiplying matrices? I would certainly not assume that C++ is better than Java (or C#).

  2. Imagine something like a dot product:

    for (int i = 0; i < n; i++) sum += a[i]*b[i];

    In C#, every time a[i] and b[i] are evaluated, code executes to verify that the index i is within the legal range of index values for the two arrays. In C++ you could do some bounds checking before you compute your inner product and then let the loop run without error checking.

    I don't know the inner workings of the C# compiler. Maybe it's smart enough to optimize away some of this error checking.

  3. I use a .Net library (Bluebit) for maths and linear algebra. It is blazingly fast. It does so many low level optimisation stuff I could never learn (and don’t give a ***) so ending up inverting matrices 250×250 in 6 ms. I made a wow to myself that anything that has O(n) should not be optimised in any way. Only thing that gets optimised are calls to database and any algorithm with O(n log n) or higher!
    To paraphrase, C# is good enough for regular stuff. Optimise where it needs to be optimised, at the algorithm level and use libraries for maths.

  4. One of the beauties of managed languages is that they are well managed. The jit is aware of the resources available at runtime and conflicting programs (at the very least other managed programs but also general memory pressure).

    So a well behaved native coder might malloc/free as things move out of scope just to be safe and not keep resources longer than necessary. The CLR can say, hey their is plenty of ram lets not waste cycles on this right now. When dealing with large datasets allocation/deallocation time can be significant.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>