Package org.apfloat.samples
Class PiDistributed
- java.lang.Object
-
- org.apfloat.samples.Pi
-
- org.apfloat.samples.PiParallel
-
- org.apfloat.samples.PiDistributed
-
public class PiDistributed extends PiParallel
Calculates pi using a cluster of servers. The servers should be runningOperationServer
. The names and ports of the cluster nodes are read from the filecluster.properties
, or aResourceBundle
by the name "cluster". The format of the property file is as follows:server1=hostname.company.com:1234 server2=hostname2.company.com:2345 server3=hostname3.company.com:3456 weight1=100 weight2=110 weight3=50
The server addresses are specified as hostname:port. Weights can (but don't have to) be assigned to nodes to indicate the relative performance of each node, to allow distributing a suitable amount of work for each node. For example,weight2
is the relative performance ofserver2
etc. The weights must be integers in the range 1...1000.Guidelines for configuring the servers:
- If the machines are not identical, give proper weights to every machine. This can improve performance greatly.
- If the machines are somewhat similar (e.g. same processor but
different clock frequency), you can calculate the weight roughly
as
clockFrequency * numberOfProcessors
. For example, a machine with two 1600MHz processors is four times as fast as a machine with one 800MHz processor. - If the machines are very heterogenous, you can benchmark their
performance by running e.g.
PiParallel
with one million digits. Remember to specify the correct number of CPUs on each machine. - Different JVMs can have different performance. For example, Sun's Java client VM achieves roughly two thirds of the performance of the server VM when running this application.
- When running
OperationServer
on the cluster nodes, specify the number of worker threads for each server to be the same as the number of CPUs of the machine. - Additionally, you should specify the number of processors
correctly in the
apfloat.properties
file for each cluster server.
Similarly as with
PiParallel
, if some nodes have multiple CPUs, to get any performance gain from running many threads in parallel, the JVM must be executing native threads. If the JVM is running in green threads mode, there is no advantage of having multiple threads, as the JVM will in fact execute just one thread and divide its time to multiple simulated threads.- Version:
- 1.9.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
PiDistributed.DistributedBinarySplittingPiCalculator
Distributed version of the binary splitting algorithm.static class
PiDistributed.DistributedChudnovskyPiCalculator
Class for calculating pi using the distributed Chudnovskys' binary splitting algorithm.static class
PiDistributed.DistributedRamanujanPiCalculator
Class for calculating pi using the distributed Ramanujan's binary splitting algorithm.protected static class
PiDistributed.Node
RemoteOperationExecutor that implements the weight property.-
Nested classes/interfaces inherited from class org.apfloat.samples.PiParallel
PiParallel.ParallelBinarySplittingPiCalculator, PiParallel.ParallelChudnovskyPiCalculator, PiParallel.ParallelRamanujanPiCalculator, PiParallel.ThreadLimitedOperation<T>
-
Nested classes/interfaces inherited from class org.apfloat.samples.Pi
Pi.AbstractBinarySplittingSeries, Pi.BinarySplittingPiCalculator, Pi.BinarySplittingProgressIndicator, Pi.BinarySplittingSeries, Pi.BorweinPiCalculator, Pi.ChudnovskyBinarySplittingSeries, Pi.ChudnovskyPiCalculator, Pi.GaussLegendrePiCalculator, Pi.RamanujanBinarySplittingSeries, Pi.RamanujanPiCalculator
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
DEBUG
private static int
MAX_WEIGHT
private static int
MIN_WEIGHT
-
Constructor Summary
Constructors Constructor Description PiDistributed()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
formatArray(java.lang.Object[] array)
static void
main(java.lang.String[] args)
Command-line entry point.
-
-
-
Field Detail
-
MIN_WEIGHT
private static final int MIN_WEIGHT
- See Also:
- Constant Field Values
-
MAX_WEIGHT
private static final int MAX_WEIGHT
- See Also:
- Constant Field Values
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.io.IOException, ApfloatRuntimeException
Command-line entry point.- Parameters:
args
- Command-line parameters.- Throws:
java.io.IOException
- In case writing the output fails.ApfloatRuntimeException
-
formatArray
private static java.lang.String formatArray(java.lang.Object[] array)
-
-