Template Meta-programming vs. Meta-object programming

Project Description

Many of the loop transformation techniques that have been presented in class have been made available in commerical Fortran compilers, but usually not in commerical C/C++ compilers. The reasons for this are (probably) two-fold. First, Fortran and C/C++ are different languages, and there are many assumptions that a compiler can make about Fortran programs that do not hold for C/C++ programs, (e.g, parameter aliasing). Second, most C/C++ compilers are not developed for the scientific computing community, and these loop/array optimizations are of limited usefulness for most C/C++ applications.

And yet, many scientific applications are developed in C/C++. How can loop transformation be made available to these applications?

One approach, sometimes called Template Meta-programming [1], involves writing template code in C++ that gets evaluated at compile time and has the effect of performing certain loop transformations, like loop unrolling. This approach works because C++'s template syntax is surprising expressive (did you know that you can write a recursive templated function for factorial in C++ that will be evaluated entirely at compile-time?). Several matrix libraries, such as POOMA [2] and Blitz++ [3] have been developed using this approach.

There are several difficulties with Template Meta-programming techniques. One is that they tend to result in extremely long and complicated template programs. This is hard on the programming and, also, on the C++ compiler (many C++ compilers segfault on these codes). Another program is that many program transformations are not easily expressed as Template Meta-programs. Thus, in order to get the full performance from these codes, certain program transformations must be provided by the underlying C++ compiler anyway!

Are there alternatives that allow application-specific compiler transformations to be made available outside of the usual commercial compiler? Perhaps.

One promising approach is to open up the C++ compiler and allow the user to add functionality to it. The OpenC++ Project [4] is an instance of this approach. With such a compiler, the user can provide customized modules to the compiler that can be targeted to optimize performance-critical regions of the user's application.

Project Goals

The goal of this project is to gain insight the advantages and disadvantages of both approaches. At the end of this project, you will be expected to argue that one approach or the other is superior, and back up your argument by comparing the complexity and performance of codes implemented using the two approaches.

What you need to do

There are several approaches that you may take:

References

  1. "Linear Algebra with C++ Template Metaprograms",  Todd Veldhuizen and Kumaraswamy Ponnambalam
  2. POOMA Home page
  3. Blitz++ Home page
  4. Openc++ Home page