03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Inheritance<br />

Chapter 6<br />

C ++ is a multi-paradigm language and the paradigm that is most strongly associated with C ++<br />

is ‘Object-Oriented Programming’ (OOP). The authors feel nevertheless that it is not the most<br />

important paradigm <strong>for</strong> scientific programming because it is inferior to generic programming<br />

<strong>for</strong> two major reasons:<br />

• Flexibility and<br />

• Per<strong>for</strong>mance.<br />

However, the impact of these two disadvantages is negligible in some situations. The per<strong>for</strong>mance<br />

is only deteriorated when we use virtual functions (§ 6.1).<br />

OOP in combination with generic programming is a very powerful mechanism to provide a <strong>for</strong>m<br />

of reusability that neither of the paradigms can provide on it own (§ 6.3–§ 6.5).<br />

6.1 Basic Principles<br />

See section ?? from page ?? to page ??.<br />

6.2 Dynamic Selection by Sub-typing<br />

solver base class<br />

The way solvers are selected in AMDiS. The MTL4 solvers generic functions. AMDiS is only<br />

slightly generic but many decisions are made at run-time (by means of pointers and virtual<br />

functions). So, we needed a way to call the generic functions but decide at run time which one.<br />

The dynamic solver selection can be done with classical C features like:<br />

#include <br />

#include <br />

class matrix {};<br />

class vector {};<br />

void cg(const matrix& A, const vector& b, vector& x)<br />

187

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!