use of org.apache.hadoop.examples.pi.math.Summation in project hadoop by apache.
the class DistSum method compute.
/** Start a job to compute sigma */
private void compute(final String name, Summation sigma) throws IOException {
if (sigma.getValue() != null)
throw new IOException("sigma.getValue() != null, sigma=" + sigma);
//setup remote directory
final FileSystem fs = FileSystem.get(getConf());
final Path dir = fs.makeQualified(new Path(parameters.remoteDir, name));
if (!Util.createNonexistingDirectory(fs, dir))
return;
//setup a job
final Job job = createJob(name, sigma);
final Path outdir = new Path(dir, "out");
FileOutputFormat.setOutputPath(job, outdir);
//start a map/reduce job
final String startmessage = "steps/parts = " + sigma.E.getSteps() + "/" + parameters.nParts + " = " + Util.long2string(sigma.E.getSteps() / parameters.nParts);
Util.runJob(name, job, parameters.machine, startmessage, timer);
final List<TaskResult> results = Util.readJobOutputs(fs, outdir);
Util.writeResults(name, results, fs, parameters.remoteDir);
fs.delete(dir, true);
//combine results
final List<TaskResult> combined = Util.combine(results);
final PrintWriter out = Util.createWriter(parameters.localDir, name);
try {
for (TaskResult r : combined) {
final String s = taskResult2string(name, r);
out.println(s);
out.flush();
Util.out.println(s);
}
} finally {
out.close();
}
if (combined.size() == 1) {
final Summation s = combined.get(0).getElement();
if (sigma.contains(s) && s.contains(sigma))
sigma.setValue(s.getValue());
}
}
use of org.apache.hadoop.examples.pi.math.Summation in project hadoop by apache.
the class DistSum method run.
/** {@inheritDoc} */
@Override
public int run(String[] args) throws Exception {
//parse arguments
if (args.length != Parameters.COUNT + 2)
return Util.printUsage(args, getClass().getName() + " <name> <sigma> " + Parameters.LIST + "\n <name> The name." + "\n <sigma> The summation." + Parameters.DESCRIPTION);
int i = 0;
final String name = args[i++];
final Summation sigma = Summation.valueOf(args[i++]);
setParameters(DistSum.Parameters.parse(args, i));
Util.out.println();
Util.out.println("name = " + name);
Util.out.println("sigma = " + sigma);
Util.out.println(parameters);
Util.out.println();
//run jobs
final Summation result = execute(name, sigma);
if (result.equals(sigma)) {
sigma.setValue(result.getValue());
timer.tick("\n\nDONE\n\nsigma=" + sigma);
return 0;
} else {
timer.tick("\n\nDONE WITH ERROR\n\nresult=" + result);
return 1;
}
}
use of org.apache.hadoop.examples.pi.math.Summation in project hadoop by apache.
the class DistBbp method execute.
/** Execute DistSum computations */
private void execute(DistSum distsum, final Map<Bellard.Parameter, Bellard.Sum> sums) throws Exception {
final List<Computation> computations = new ArrayList<Computation>();
int i = 0;
for (Bellard.Parameter p : Bellard.Parameter.values()) for (Summation s : sums.get(p)) if (s.getValue() == null)
computations.add(distsum.new Computation(i++, p.toString(), s));
if (computations.isEmpty())
Util.out.println("No computation");
else {
timer.tick("execute " + computations.size() + " computation(s)");
Util.execute(distsum.getParameters().nThreads, computations);
timer.tick("done");
}
}
use of org.apache.hadoop.examples.pi.math.Summation in project hadoop by apache.
the class SummationWritable method readFields.
/** {@inheritDoc} */
@Override
public void readFields(DataInput in) throws IOException {
final ArithmeticProgression N = ArithmeticProgressionWritable.read(in);
final ArithmeticProgression E = ArithmeticProgressionWritable.read(in);
sigma = new Summation(N, E);
if (in.readBoolean()) {
sigma.setValue(in.readDouble());
}
}
use of org.apache.hadoop.examples.pi.math.Summation in project hadoop by apache.
the class TaskResult method valueOf.
/** Covert a String to a TaskResult */
public static TaskResult valueOf(String s) {
int i = 0;
int j = s.indexOf(", duration=");
if (j < 0)
throw new IllegalArgumentException("i=" + i + ", j=" + j + " < 0, s=" + s);
final Summation sigma = Summation.valueOf(Util.parseStringVariable("sigma", s.substring(i, j)));
i = j + 2;
j = s.indexOf("(", i);
if (j < 0)
throw new IllegalArgumentException("i=" + i + ", j=" + j + " < 0, s=" + s);
final long duration = Util.parseLongVariable("duration", s.substring(i, j));
return new TaskResult(sigma, duration);
}
Aggregations