-
Book Overview & Buying
-
Table Of Contents
Extending and Modifying LAMMPS Writing Your Own Source Code
By :

In this section, we demonstrate the MPI process with an example of approximating the value of
using broadcast and reduction operations of group communication. We observe that
can be calculated by evaluating the following integral:
Substituting
, we get the following:
Therefore, the area contained between x=0 and x=1 under the f(x) curve gives the value of
, as illustrated in the following graph:
Figure 14.8 – Approximation of the area under
in the range 
As you can see, this area can be approximated by the area of N rectangular slices, as shown in the graph, with each slice occupying a width of 1/N.
The approximation for
is therefore expressed as a sum of rectangle areas, where the width of each rectangle is 1/N and the height is the value f(x) at the midpoint of each rectangle:
The following screenshot shows the C++ code (calcpi.cpp) that calculates...