Anda di halaman 1dari 3

Justin Fry

CSSE/MA 335
Solving Ordinary Differential Equations in C++ and MPI
Ordinary differential equations (or ODEs) are equations which contain a function of a
variable and its derivative. They are used nearly universally among all the scientific
fields due to the prevalence of rates of change. They type of ODE which will be dealt
with for the purposes of this paper is what is referred to as an Initial Value Problem
(IVP), which consists of an ODE and a pair of values which determines the initial
state of the problem. Unfortunately, many of these ODEs can only be solved
numerically as opposed to analytically. Numerical solvers are repetitive by nature
and thus can quickly become tedious and time consuming when done by hand
especially as the complexity and size of the equation in question increases. This has
led to wide demand in the development of computer algorithms able to efficiently
and accurately numerically solve such equations, and luckily due to their repetitive
nature they are aptly suited to the task. Typical numerical solvers for ODEs involve
evaluating the mth derivative of the dependent variable x(t) at some point n and
then manipulated in a fashion with a known point x(n) to obtain an estimated
value for the point x(n+1). The process is then iterated until the desired point is
achieved. The most popular numeric solver currently used is most likely the RungeKutta fourth order method.
To fully understand the available methods we must take a look at the features
that differentiate them. The primary features consist of single or multistep methods,
invariable/variable step-size methods, variable order methods, error indication, and
stiffness. Multistep methods use more than simply the most recent previously
calculated value of x(n) to calculate x(n+1), including multiple results in this
manner results in a more accurate estimation. The step-size of the method is the
rate at which it is iterated. Variable step-size methods allow the number of steps in
a certain locality of a function to increase or decrease due to the error that would be
generated in estimating that region. If a particular region is especially chaotic you
can use a small step size to reflect that change. Variable order methods are similar
to variable step-size methods in that they dynamically select methods of greater or
less precision based upon the error data for the upcoming step, this is used to
create more accurate and efficient algorithms. Error indication is necessary for any
method which wishes to have adaptation to the changing local complexity of the
function and is therefore implemented in most methods. Lastly a stiff system is one
which, when some numeric methods are applied to it, exhibits instability in the
solution. Instability occurs when the application of a numerical solver results in a
larger error size than would be typically by other methods. To accommodate these
stiff systems, methods will change the algorithm used based upon the cases which
result in instability. For the purposes of this paper, we will be analyzing and
implementing only the RK4 and parallel Adams-Bashforth method as these features
do not directly affect the parallelization.
The RK4 method of integrating in serial is relatively simple, it consists of a
stepper function which calculates the value of a single step of the method, and an
integrate function, which iterates through the steps making up the interval you are
integrating along. To take a look at the stepper function we need to see the actual
math behind rk4. If we have our initial value problem y=f(x,y), y0, x0, we

approximate for yn by solving for four stages within each step, K 1-4, like so (where h
is the step size): K1= f(xn-1,yn-1) , K2=h*f(xn-1+h/2, yn-1+h*k1/2), k3 = h*f(xn1+h/2, yn-1+h*k2/2), k4 = h*f(xn-1+h, yn-1+h*k3) where yn = yn-1 +
(K1+2K2+2K3+K4)/6. As you can see, due to the references to previous k values in
each stage this remains a fully sequential problem. In order to make this problem
solvable in parallel, it is necessary to reuse values from the previous steps. This is
precisely what the Adams-Bashforth method accomplishes. Instead of using a
multistage algorithm such as RK4, by using a multi-step algorithm, all of the terms
in the current calculation are based off of data in previous steps allowing each
processor to have a term it can compute in parallel. A third order Adams-Bashforth
scheme consists of one term from N, one from N-1 and finally one from N-2. It
should be noted that it is, in fact, possible to manipulate the RK4 method to allow it
to become parallel across the method, however, not all of the stages can become
parallelized and it requires a great deal of effort although it does result in some very
stable methods and is done by decoupling the blocks.

Efficiency Analysis:
I implemented the adams-bashforth method of explicit discretization in a very
modular way which I believe may have adversely effected the efficiency in low
demand computations. My implementation allows the user to choose the order of
the method which they wish to use. This allows the user to more closely control the
accuracy and parallelization of the code. It was done by simply creating a file
containing the coefficient values for the various orders. The load period of the work
consists mainly of retrieving and distributing basic variables and the contents of the
coefficient matrix. Once the loading is complete it begins to start the work phase.
Due to the value requirements of high order Adamsbashforth methods it is
necessary to start with only a first order calculation running on the root node,
linearly increasing the order per step until the desired order is possible, it then
maintains that order. Each processor handles (order/size) terms of the time step
adds these terms and then delivers the summation to the root node for final
manipulations to get an estimation for a point value. Once the root node gets a
value for Yn it broadcasts it to its peers to begin its next step. While this works
perfectly for finding the values needed, it is unfortunately quite slow. This is due to
the fact that the amount of processing power required on any individual processor
to calculate their terms is quite low when compared to the cost of communication
between those processors. With simple small systems it is much more efficient to
simply run a serial algorithm. However, it can be reasonably assume that given
larger systems of equations, the speed up from the parallel processing would begin
to outweigh the cost of communication. Unfortunately, due to the nature of the
Adams bashforth method, where each step is dependent up on the result of the
previous, it would not be possible to remove this bottleneck.
processors

order
1
1
1

load time
work time
Speedup
0.000141
1
571
0.00264964
0.000119
2
544
0.00256906
3 0.000112
0.00255294

efficiency

10

10

252
0.000124
46
0.000110
369
0.000272
788
0.000115
146
0.000121
752
0.000115
459
0.000137
47
0.000101
295
0.000168
243
0.000126
85
0.000142
075
0.000104
77
0.000235
715
0.000130
129

0.00233433
0.00225338
0.00227864
0.00223607
0.0023121
0.0022873
0.0357414
0.124576

2%

0.010311216

0.000339142

688%

3.44152302

0.000397386

582%

2.909136205

0.0709862

4%

0.011987964

0.154063

1%

0.004948841

0.173246

1%

0.003336441

0.130307

27%

0.054857222

Anda mungkin juga menyukai