我想在hadoop上实现一个并行计算。基本上,parallel-for接收一个子骨架(它可以是一个类似map()的函数)和一个整数作为参数。子骨架将按照整数参数指定的次数执行。对子骨架的一次调用的结果作为参数传递给随后的对子骨架的调用。最后,最后一个子骨架的结果被提供为并行结果。下面是一个Scandium库(http://skandium.niclabs.cl/)上的实现示例,我很乐意将这个实现移植到hadoop上。
* @param <P> The input and result type of the {@link Skeleton}.
* */
public class For<P> extends AbstractSkeleton<P,P> {
Skeleton<P,P> subskel;
int times;
/**
* The constructor.
*
* @param skeleton The skeleton pattern to execute.
* @param times The number of times to execute the skeleton.
*/
public For(Skeleton<P,P> skeleton, int times){
this.subskel=skeleton;
this.times = times;
}
/**
* The constructor.
*
* @param execute The skeleton pattern to execute.
* @param times The number of times to execute the {@link Muscle}.
*/
public For(Execute<P,P> execute, int times){
this(new Seq<P,P>(execute), times);
}
/**
* {@inheritDoc}
*/
public void accept(SkeletonVisitor visitor) {
visitor.visit(this);
}
}发布于 2011-12-28 10:22:12
如果我没理解错的话,您希望执行一个函数N次,每次调用都接收前一次调用的输出作为输入。
这种函数调用的链接本质上是串行的。没有(一般的)方法来并行化它。
我能看到的唯一希望是,如果函数和输入的性质(您还没有指定)允许对函数的单个调用进行并行化,那么您可以这样做,并在作业控制级别进行迭代/链接。这就是说:如果您的输入是一个数据集,而您的函数是对该数据集的某个转换,其输出是该函数的合法输入,并且如果此转换可以并行化,那么这里可能有一种使用Hadoop的方法。
如果您能提供更多细节,我将很乐意为您提供更具体的建议。
https://stackoverflow.com/questions/6446914
复制相似问题