或者通常在并行操作和顺序操作之间做出决定。由于开销的原因,在不测试的情况下很难知道并行实现还是顺序实现是最好的。显然,训练“决策者”使用哪种方法需要一些时间。我要说的是,这种方法不可能是完美的,所以它本质上是概率的。x,y,z确实会影响“决策者”。我认为一个非常天真的实现是在一开始就给两个1/2机会,然后根据过去的表现开始偏爱它们。这忽略了x,y,z,无论如何,请分享你的启发式,你的经验,如果有的话,你的提示。
示例代码:
public interface IComputer {
decimal Compute(decimal x, decimal y, decimal z);
}
public class SequentialComputer : IComputer {
public decimal Compute( ... // sequential implementation
}
public class ParallelComputer : IComputer {
public decimal Compute( ... // parallel implementation
}
public class HybridComputer : IComputer {
private SequentialComputer sc;
private ParallelComputer pc;
private TheDecider td; // Helps to decide between the two.
public HybridComputer() {
sc = new SequentialComputer();
pc = new ParallelComputer();
td = TheDecider();
}
public decimal Compute(decimal x, decimal y, decimal z) {
decimal result;
decimal time;
if (td.PickOneOfTwo() == 0) {
// Time this and save result into time.
result = sc.Compute(...);
} else {
// Time this and save result into time.
result = pc.Compute();
}
td.Train(time);
return result;
}
}发布于 2010-06-11 12:48:47
我会删除计算机的专门化,在你的PLINQ代码上使用WithDegreeOfParallelism。如果你的决策器了解到没有并行是最优的,就让它返回1。
https://stackoverflow.com/questions/3020096
复制相似问题