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.

16 CHAPTER 1. GOOD AND BAD SCIENTIFIC SOFTWARE<br />

than C ++. Yes, C ++ can look like this if one puts enough ef<strong>for</strong>t in good software.<br />

Evidently, it is also much easier to write algorithms at this abstraction level than expressing it<br />

with low-level operations.<br />

The Purpose of Scienfic Software<br />

<strong>Scientists</strong> shall do science.<br />

Excellent scientific software is expressed only in mathematical and domainspecific<br />

operations without any technical detail exposed.<br />

At this abstraction level, scientists can focus on models and algorithms, being<br />

much more productive and progress scientific discovery.<br />

Nobody knows how many scientists wasting how much time every year dwelling on small technical<br />

details of bad software like in Listing 1.1. Of course, the technical details have to be realized<br />

in some place but not in a scientific application. This is the worst possible location. Use a<br />

two-level approach: write your applications in terms of expressive mathematical operations and<br />

if they do not exist, implement them separately. These mathematical operations must be carefully<br />

implemented <strong>for</strong> maximal per<strong>for</strong>mance or use other operations with maximal per<strong>for</strong>mance.<br />

Investing time in the per<strong>for</strong>mance of these fundamental operations is highly rentable because<br />

the functions will be reused very often.<br />

Advise<br />

Use the right abstractions!<br />

If they do not exist, implement them.<br />

Speaking of abstractions, the CG implementation in Listing 1.2 does not commit to any technical<br />

detail. In no place, the function is restricted to a numerical type like double. It works as well<br />

<strong>for</strong> float, GNU’s multiprecision, complex, interval arithmetic, quaternions, . . .<br />

The matrix A can have any internal <strong>for</strong>mat, as long as it can be multiplied with a vector<br />

it can be used in the function. In fact, it does not even need to be matrix but can be any<br />

linear operator. For instance, an object that per<strong>for</strong>ms a Fast Fourier Trans<strong>for</strong>mation (FFT)<br />

on a vector can be used as A when the FFT is expressed by a product of A with the vector.<br />

Similarly, the vectors do not need to be represented by finite-dimensional arrays but can be<br />

elements of any vector space that is somehow computer-representable as long as all operations<br />

in the algorithm can be per<strong>for</strong>med.<br />

We are also open to other computer architectures. If the matrix and the vectors are distributed<br />

over the nodes of a parallel supercomputer and according parallel operations are available, the<br />

functions runs in parallel without changing any single line. (GP)GPU acceleration can be also<br />

realized within the data structures and their operations without changing the algorithm. In

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

Saved successfully!

Ooh no, something went wrong!