How should scientific codes be constructed? Scientific codes are often experimental in nature, and therefore need to be easy to change, and, of course, quick to develop in the first place—who wants to invest any more than necessary into an idea that might not work out after all? On the other hand, computational scientists are an impatient bunch: Once the method stabilizes, or it becomes clear that it is generally useful, more and more demands get placed on a prototype code, most of all speed. It is clearly desirable to respond to these demands in an evolutionary manner. Why rewrite an entire code, possibly in a different language, if only one small part is responsible for most of the run time?

One answer that I have found to address these problems well is what I call hybrid development. Nearly all my code these days is “hybrid”. Now what does that mean? That means, I start developing in a high-level language that is quick to modify and separates me from the more menial tasks of coding, allowing me to code and test an algorithm quickly. The cost for this quick development turnaround is that the initial prototype is often fairly slow because many small operations are performed in the (often interpreted, instead of compiled) high-level language. This is an effect that everybody who has developed larger-scale code in MATLAB or similar environments has seen. Often, the bulk of the run time is concentrated in 10% or less of the entire code. In this case, the sensible solution is to replace the slow part of the high-level code with a lower-level compiled implementation, while keeping as much of the existing high-level code intact. This is the idea of hybrid development.

MATLAB supports this idea to some extent with its MEX mechanism. There are however many more powerful tools on the market (and available for free) that make hybrid development easier and faster by orders of magnitude. In a future installment of this mini-series, I will highlight the software environment I use for my hybrid codes, and point out what I believe its advantages over other solutions are.