org.apache.hadoop.examples
Class PiEstimator

java.lang.Object
  extended by org.apache.hadoop.conf.Configured
      extended by org.apache.hadoop.examples.PiEstimator
All Implemented Interfaces:
Configurable, Tool

public class PiEstimator
extends Configured
implements Tool

A Map-reduce program to estimate the value of Pi using quasi-Monte Carlo method. Mapper: Generate points in a unit square and then count points inside/outside of the inscribed circle of the square. Reducer: Accumulate points inside/outside results from the mappers. Let numTotal = numInside + numOutside. The fraction numInside/numTotal is a rational approximation of the value (Area of the circle)/(Area of the square), where the area of the inscribed circle is Pi/4 and the area of unit square is 1. Then, Pi is estimated value to be 4(numInside/numTotal).


Nested Class Summary
static class PiEstimator.PiMapper
          Mapper class for Pi estimation.
static class PiEstimator.PiReducer
          Reducer class for Pi estimation.
 
Constructor Summary
PiEstimator()
           
 
Method Summary
static BigDecimal estimate(int numMaps, long numPoints, JobConf jobConf)
          Run a map/reduce job for estimating Pi.
static void main(String[] argv)
          main method for running it as a stand alone command.
 int run(String[] args)
          Parse arguments and then runs a map/reduce job.
 
Methods inherited from class org.apache.hadoop.conf.Configured
getConf, setConf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.conf.Configurable
getConf, setConf
 

Constructor Detail

PiEstimator

public PiEstimator()
Method Detail

estimate

public static BigDecimal estimate(int numMaps,
                                  long numPoints,
                                  JobConf jobConf)
                           throws IOException
Run a map/reduce job for estimating Pi.

Returns:
the estimated value of Pi
Throws:
IOException

run

public int run(String[] args)
        throws Exception
Parse arguments and then runs a map/reduce job. Print output in standard out.

Specified by:
run in interface Tool
Parameters:
args - command specific arguments.
Returns:
a non-zero if there is an error. Otherwise, return 0.
Throws:
Exception

main

public static void main(String[] argv)
                 throws Exception
main method for running it as a stand alone command.

Throws:
Exception


Copyright © 2009 The Apache Software Foundation