Three different versions of an application for calculating π are
included. The simplest,
Pi runs on one
computer using one processor (and one thread) only.
executes multiple threads in parallel and has vastly better performance
on multi-core computers. Finally,
can use multiple separate computers for calculating pi with even
greater processing power.
As a curiosity, two applets are provided for running
PiParallel through a graphical user
correspondingly. These programs can also be run as stand-alone
Compared to the C++ version of apfloat, the Java version pi calculation program is usually just as fast. Even in worst cases the Java version achieves roughly 50% of the performance of the assembler-optimized C++ versions of apfloat. Modern JVMs are nearly as efficient as optimizing C++ compilers in code generation. The advantage that JVMs have over native C++ compilers is obviously that the JVM generates optimal code for every target architecture and runtime profile automatically, from an intermediate portable binary executable format. With C++, the source code must be compiled and profiled manually for every target architecture, which can be difficult and tedious.
On multi-core computers the Java parallel pi calculator is often significantly faster than the C++ parallel version. The same applies to the distributed pi calculator. Multi-threaded and distributed applications are more efficient to implement in Java due to C++'s historical lack of standard libraries for threading and networking.
Interface Summary Interface Description Operation<T>Interface for implementing arbitrary operations to be executed. OperationExecutorInterface for implementing objects that can execute
Pi.BinarySplittingSeriesTerms for the binary splitting series. PiAWT.StatusIndicatorInterface to indicate an error status in the application.
Class Summary Class Description ApfloatHolderSimple JavaBean to hold one
BackgroundOperation<T>Class for running an
Operationin the background in a separate thread.
LocalOperationExecutorClass to execute
OperationServerServer for executing
Operations from remote calls.
PiCalculates pi using four different algorithms. Pi.AbstractBinarySplittingSeriesAbstract base class for the binary splitting series. Pi.BinarySplittingPiCalculatorClass for implementing the binary splitting algorithm. Pi.BinarySplittingProgressIndicatorIndicates progress of the pi calculation using the binary splitting algorithm. Pi.BorweinPiCalculatorCalculates pi using the Borweins' quartic algorithm. Pi.ChudnovskyBinarySplittingSeriesChudnovskys' algorithm terms for the binary splitting series. Pi.ChudnovskyPiCalculatorBasic class for calculating pi using the Chudnovskys' binary splitting algorithm. Pi.GaussLegendrePiCalculatorCalculates pi using the Gauss-Legendre algorithm. Pi.RamanujanBinarySplittingSeriesRamanujan's algorithm terms for the binary splitting series. Pi.RamanujanPiCalculatorBasic class for calculating pi using the Ramanujan binary splitting algorithm. PiAppletApplet for calculating pi using four different algorithms. PiAWTGraphical AWT elements for calculating pi using four different algorithms. PiDistributedCalculates pi using a cluster of servers. PiDistributed.DistributedBinarySplittingPiCalculatorDistributed version of the binary splitting algorithm. PiDistributed.DistributedChudnovskyPiCalculatorClass for calculating pi using the distributed Chudnovskys' binary splitting algorithm. PiDistributed.DistributedRamanujanPiCalculatorClass for calculating pi using the distributed Ramanujan's binary splitting algorithm. PiDistributed.NodeRemoteOperationExecutor that implements the weight property. PiGUIAWT client application for calculating pi using four different algorithms. PiParallelCalculates pi using multiple threads in parallel. PiParallel.ParallelBinarySplittingPiCalculatorParallel version of the binary splitting algorithm. PiParallel.ParallelChudnovskyPiCalculatorClass for calculating pi using the parallel Chudnovskys' binary splitting algorithm. PiParallel.ParallelRamanujanPiCalculatorClass for calculating pi using the parallel Ramanujan's binary splitting algorithm. PiParallel.ThreadLimitedOperation<T>Class to execute operations while setting
ApfloatContext.setNumberOfProcessors(int)to some value.
PiParallelAppletApplet for calculating pi using multiple threads in parallel. PiParallelAWTGraphical AWT elements for calculating pi using multiple threads in parallel. PiParallelGUIAWT client application for calculating pi using multiple threads in parallel. RemoteOperationExecutor