Fdi 2008 Lecture4
Fdi 2008 Lecture4
Fdi 2008 Lecture4
John Burkardt1
1 Virginia Tech
Rb
The INT task: estimate a f (x) dx.
A naive way to approximate an integral multiplies the average of
many values of f (x) by the length of the interval (b − a).
Complications arise if f (x) is hard to evaluate, or if its behavior
varies in parts of the interval.
Another issue arises if we need an accurate estimate, and intend to
average as many values as necessary to get there.
Rb
The MC-INT task: estimate a f (x) dx.
The integral can be estimated by evaluating f (x) at points
randomly selected in [a, b], and multiply the average value by the
length of the interval b − a.
A general multidimensional integral over D can be estimated in the
same way, by evaluating f (x, y , z) at points randomly selected
from D, and multiplying the average value by the volume of D.
Interesting features:
works the same in any spatial dimension.
works the same for irregular regions.
the computation includes an estimate of its accuracy.
no matter how many samples have been taken, the user can stop
with a valid estimate, or take more samples for an improved
estimate.
the computation is embarassingly parallel.
(This clever sum counts all neighbor pairs just once, assuming
wraparound at the boundaries.)
For 0 < T , the system will organize itself into regions of positive
and negative spin.
∂H ∂2H
− k 2 = f (x, t)
∂t ∂x
Parallel processing is actually useful for this problem!
∂2H (H(i−1)−2H(i)+H(i+1))
replace ∂x 2
by ∆x 2
.
∂H HNEW (i)−H(i)
replace ∂t by ∆t
Now, at each node, you have a formula for computing the new
value of H(i) based on data at the old time.
The computations of the values at the next time are independent,
and can be done in parallel.
For a distributed memory version, perhaps using domain
decomposition, each processor lets its two neighbors know the
updated internal boundary values.
Apply forces:
gravity
electric field
van der Waal attraction
Update locations and velocities.
Parallelizable, but need to communicate new locations frequently.
The DOT, MV and MM tasks are very clean, very busy linear
algebra operations.
They are easy to analyze and program.
But even these ”almost perfectly straightforward” tasks can be
programmed well or poorly!
integer i , j , n
real a(n , n ) , x (n ) , y(n)
do i = 1 , n
y ( i ) = 0.0
do j = 1 , n
y( i ) = y( i ) + a( i , j ) ∗ x( j )
end do
end do
integer i , j , n
real a(n , n ) , x (n ) , y(n)
do i = 1 , n
y ( i ) = 0.0
end do
do j = 1 , n
do i = 1 , n
y( i ) = y( i ) + a( i , j ) ∗ x( j )
end do
end do
1 In equation 1, use old values for x(2) through x(n), and solve
for new x(1);
2 In equation 2, use old values for x(1), and x(3) through x(n),
and solve for new x(2);
3 ...and so on until...
4 In equation n, use old values for x(1) through x(n − 1), and
solve for new x(n)
At the end of this process (and only then!) replace all the old
values by the new values.
Then repeat the solution step.