我想在hadoop上实现parallel-for in。基本上parallel-for接收子骨架(它可以是map())和整数作为参数。子骨架将执行整数参数指定的次数。一次调用子骨架的结果作为参数传递给子骨架的以下调用。最终,最后一个子骨架的结果作为parallel-for结果提供。下面是一个关于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);
}
}
答案 0 :(得分:0)
如果我正确理解了这个问题,你想要执行一个N次函数,每次调用都接收上一次调用的输出作为输入。
这种函数调用的链接本质上是串行的。没有(通用)方法来并行化它。
我能看到的唯一希望是,如果函数和输入的性质(你没有指定)允许对函数的单个调用进行并行化,那么你可以这样做,并进行迭代/链接在工作控制层面。这就是说:如果你的输入是一个数据集,你的函数是对该数据集的一些转换,其输出是函数的合法输入,如果这个转换可以并行化,那么可能有办法在这里使用Hadoop。
如果您可以提供更多详细信息,我将很乐意通过更具体的建议更新此答案。