本文整理汇总了Java中org.apache.hadoop.examples.pi.math.Bellard类的典型用法代码示例。如果您正苦于以下问题:Java Bellard类的具体用法?Java Bellard怎么用?Java Bellard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bellard类属于org.apache.hadoop.examples.pi.math包,在下文中一共展示了Bellard类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.hadoop.examples.pi.math.Bellard; //导入依赖的package包/类
/** main */
public static void main(String[] args) throws IOException {
if (args.length < 2 || args.length > 3)
Util.printUsage(args, Parser.class.getName()
+ " <b> <inputpath> [<outputdir>]");
int i = 0;
final long b = Util.string2long(args[i++]);
final String inputpath = args[i++];
final String outputdir = args.length >= 3? args[i++]: null;
//read input
final Map<Parameter, List<TaskResult>> parsed = new Parser(true).parse(inputpath, outputdir);
final Map<Parameter, TaskResult> combined = combine(parsed);
long duration = 0;
for(TaskResult r : combined.values())
duration += r.getDuration();
//print pi
final double pi = Bellard.computePi(b, combined);
Util.printBitSkipped(b);
Util.out.println(Util.pi2string(pi, Bellard.bit2terms(b)));
Util.out.println("cpu time = " + Util.millis2String(duration));
}
示例2: execute
import org.apache.hadoop.examples.pi.math.Bellard; //导入依赖的package包/类
/** 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");
}
}
示例3: run
import org.apache.hadoop.examples.pi.math.Bellard; //导入依赖的package包/类
/** {@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;
}