Search in sources :

Example 1 with Parameter

use of org.apache.hadoop.examples.pi.math.Bellard.Parameter in project hadoop by apache.

the class DistBbp method run.

/** {@inheritDoc} */
public int run(String[] args) throws Exception {
    //parse arguments
    if (args.length != DistSum.Parameters.COUNT + 1)
        return Util.printUsage(args, getClass().getName() + " <b> " + Parameters.LIST + "\n  <b> The number of bits to skip, i.e. compute the (b+1)th position." + Parameters.DESCRIPTION);
    int i = 0;
    final long b = Util.string2long(args[i++]);
    final DistSum.Parameters parameters = DistSum.Parameters.parse(args, i);
    if (b < 0)
        throw new IllegalArgumentException("b = " + b + " < 0");
    Util.printBitSkipped(b);
    Util.out.println(parameters);
    Util.out.println();
    //initialize sums
    final DistSum distsum = new DistSum();
    distsum.setConf(getConf());
    distsum.setParameters(parameters);
    final boolean isVerbose = getConf().getBoolean(Parser.VERBOSE_PROPERTY, false);
    final Map<Parameter, List<TaskResult>> existings = new Parser(isVerbose).parse(parameters.localDir.getPath(), null);
    Parser.combine(existings);
    for (List<TaskResult> tr : existings.values()) Collections.sort(tr);
    Util.out.println();
    final Map<Bellard.Parameter, Bellard.Sum> sums = Bellard.getSums(b, parameters.nJobs, existings);
    Util.out.println();
    //execute the computations
    execute(distsum, sums);
    //compute Pi from the sums 
    final double pi = Bellard.computePi(b, sums);
    Util.printBitSkipped(b);
    Util.out.println(Util.pi2string(pi, Bellard.bit2terms(b)));
    return 0;
}
Also used : Parameter(org.apache.hadoop.examples.pi.math.Bellard.Parameter) List(java.util.List) ArrayList(java.util.ArrayList) Parameters(org.apache.hadoop.examples.pi.DistSum.Parameters)

Example 2 with Parameter

use of org.apache.hadoop.examples.pi.math.Bellard.Parameter in project hadoop by apache.

the class Parser method parse.

/** Parse a path */
private Map<Parameter, List<TaskResult>> parse(String f) throws IOException {
    final Map<Parameter, List<TaskResult>> m = new TreeMap<Parameter, List<TaskResult>>();
    for (Parameter p : Parameter.values()) m.put(p, new ArrayList<TaskResult>());
    parse(new File(f), m);
    //LOG.info("m=" + m.toString().replace(", ", ",\n  "));
    for (Parameter p : Parameter.values()) m.put(p, m.get(p));
    return m;
}
Also used : ArrayList(java.util.ArrayList) Parameter(org.apache.hadoop.examples.pi.math.Bellard.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) File(java.io.File)

Example 3 with Parameter

use of org.apache.hadoop.examples.pi.math.Bellard.Parameter in project hadoop by apache.

the class Parser method combine.

/** Combine results */
static <T extends Combinable<T>> Map<Parameter, T> combine(Map<Parameter, List<T>> m) {
    final Map<Parameter, T> combined = new TreeMap<Parameter, T>();
    for (Parameter p : Parameter.values()) {
        //note: results would never be null due to the design of Util.combine
        final List<T> results = Util.combine(m.get(p));
        Util.out.format("%-6s => ", p);
        if (results.size() != 1)
            Util.out.println(results.toString().replace(", ", ",\n           "));
        else {
            final T r = results.get(0);
            combined.put(p, r);
            Util.out.println(r);
        }
    }
    return combined;
}
Also used : Parameter(org.apache.hadoop.examples.pi.math.Bellard.Parameter) TreeMap(java.util.TreeMap)

Aggregations

Parameter (org.apache.hadoop.examples.pi.math.Bellard.Parameter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 File (java.io.File)1 Parameters (org.apache.hadoop.examples.pi.DistSum.Parameters)1