Scientific and Engineering C++: Two Faces of Polymorphism

In this column we compare two forms of polymorphism side-by-side for a problem that either form can tackle. The template form uses common names in similar classes; the virtual function form uses common function prototypes in base classes. The problem requires neither accessing elements of collections through base class pointers-a forte of virtual functions-nor does it have many small objects that need efficient random access-a forte of templates. The choice between virtual function and template polymorphism being non-obvious, it is instructive to compare these two forms of polymorphism on the one problem. The problem is to generalize the LAPACK wrapper classes we've discussed in our last two columns [1,2]. From a software design point of view, our wrapper classes are usability coating on a high performance core provided by LAPACK's FORTRAN code. We won't discuss the core here; we want to focus on the software, not the math. Overall the problem we tacle has two input objects, a matrix of equation coefficients A and a matrix of equation results b. THe output is a matrix of solution values, x, where Ax = b. The method of solution is to factor A into matrices that are easily inverted, e.g., A = LU, then to solve the factored equations, e.g., x = U-(1)L-(1)b.

By: John J. Barton and Lee R. Nackman

Published in: RC20192 in 1995

LIMITED DISTRIBUTION NOTICE:

This Research Report is available. This report has been submitted for publication outside of IBM and will probably be copyrighted if accepted for publication. It has been issued as a Research Report for early dissemination of its contents. In view of the transfer of copyright to the outside publisher, its distribution outside of IBM prior to publication should be limited to peer communications and specific requests. After outside publication, requests should be filled only by reprints or legally obtained copies of the article (e.g., payment of royalties). I have read and understand this notice and am a member of the scientific community outside or inside of IBM seeking a single copy only.

7827.ps.gz

Questions about this service can be mailed to reports@us.ibm.com .