Introduction
This sample application demonstrates how to use Intel® MPI Library with Java* to calculate the pi value using the Leibniz formula.
Available Downloads
- Linux*
- Size: 1.8 KB
- SHA1: D7C108989CC5B1D2AD005CD49DCAAE88E3EFAD5C
Detailed Description
- Intel® MPI Library provides an experimental feature to enable support for Java* MPI applications. Intel MPI Library provides Java bindings for a subset of MPI-2 routines. This sample application demonstrates how to use Intel MPI Library with Java to calculate the pi value using the Leibniz formula.
- This Java code imports Intel MPI Library to initialize MPI and perform the Leibniz formula.
- This Leibniz formula is used to calculate pi in this example. It's an infinite series method for calculating pi, which requires a large amount of iterations to produce an accurate value of pi.
- In the code, intervals are defined for the calculation of pi as 100000; each process will calculate partial sum for the number of iterations equal to intervals divided by the number of processes in the communicator(MPI_COMM_WORLD). The partial sums calculated by each of the processes is added to obtain the total sum, which is then multiplied by 4 and printed in 10long float.
- The Leibniz formula operates for calculating pi as follows:
partial sum = for first iteration 1, for second 1 - 1/3 , so on ..
π/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ... (this is the total sum)
Or,
π = 4 ( 1 - 1/3 + 1/5 - 1/7 + 1/9 - ... )
For more information on building and running Intel MPI Library applications with Java, refer to the following documentation:
Disclaimers1
Product and Performance Information
Intel is in the process of removing non-inclusive language from our current documentation, user interfaces, and code. Please note that retroactive changes are not always possible, and some non-inclusive language may remain in older documentation, user interfaces, and code.