C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden C++ for Scientists - Technische Universität Dresden

math.tu.dresden.de
from math.tu.dresden.de More from this publisher
03.12.2012 Views

252 CHAPTER 11. C++ LIBRARIES FOR SCIENTIFIC COMPUTING

Real-World Programming Chapter 12 12.1 Transcending Legacy Applications Legacy application has been written in plain ANSI C or are available as Fortran libraries. It is therefore highly desirable to rejuvenate the implementation which is already available so that it utilizes advanced technologies and techniques while at the same time keeping as much of the already obtained experience and trust related to the original code base. One approach for the transition is possible by an evolutionary fashion initially including as much of the old implementation as possible and gradually replacing it to bring it up to date. The following examples are based on a particle simulator, where to important concepts can be separated: scattering mechanisms (physical behaviour of particles at boundaries (TODO: PS)) and physical model descriptions (how particles interact (TODO: PS) ). All available scattering mechanisms are implemented as individual functions, which are called subsequently. The scattering models require a variable set of parameters, which leads to non-homogeneous interfaces in the functions representing them. To alleviate this to some extent global variables have been employed completely eliminating any aspirations of data encapsulation and posing a serious problem for attempts for parallelization to take advantage of modern multi-core CPUs. The code has the very simple and repetitive structure: double sum = 0; double current rate = generate random number(); if (A key == on) { sum = A rate(state, parameters); if (current rate < sum) { counter→ A[state→ valley]++; state after A (st, p); return; } } sum += B rate (state, state 2, parameters); 253

Real-World Programming<br />

Chapter 12<br />

12.1 Transcending Legacy Applications<br />

Legacy application has been written in plain ANSI C or are available as Fortran libraries. It is<br />

there<strong>for</strong>e highly desirable to rejuvenate the implementation which is already available so that<br />

it utilizes advanced technologies and techniques while at the same time keeping as much of<br />

the already obtained experience and trust related to the original code base. One approach<br />

<strong>for</strong> the transition is possible by an evolutionary fashion initially including as much of the old<br />

implementation as possible and gradually replacing it to bring it up to date.<br />

The following examples are based on a particle simulator, where to important concepts can be<br />

separated: scattering mechanisms (physical behaviour of particles at boundaries (TODO: PS))<br />

and physical model descriptions (how particles interact (TODO: PS) ). All available scattering<br />

mechanisms are implemented as individual functions, which are called subsequently. The scattering<br />

models require a variable set of parameters, which leads to non-homogeneous interfaces<br />

in the functions representing them. To alleviate this to some extent global variables have been<br />

employed completely eliminating any aspirations of data encapsulation and posing a serious<br />

problem <strong>for</strong> attempts <strong>for</strong> parallelization to take advantage of modern multi-core CPUs. The<br />

code has the very simple and repetitive structure:<br />

double sum = 0;<br />

double current rate = generate random number();<br />

if (A key == on)<br />

{<br />

sum = A rate(state, parameters);<br />

if (current rate < sum)<br />

{<br />

counter→ A[state→ valley]++;<br />

state after A (st, p);<br />

return;<br />

}<br />

}<br />

sum += B rate (state, state 2, parameters);<br />

253

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

Saved successfully!

Ooh no, something went wrong!