首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在运行时决定使用PLINQ和LINQ?

如何在运行时决定使用PLINQ和LINQ?
EN

Stack Overflow用户
提问于 2010-06-11 11:55:44
回答 1查看 131关注 0票数 3

或者通常在并行操作和顺序操作之间做出决定。由于开销的原因,在不测试的情况下很难知道并行实现还是顺序实现是最好的。显然,训练“决策者”使用哪种方法需要一些时间。我要说的是,这种方法不可能是完美的,所以它本质上是概率的。x,y,z确实会影响“决策者”。我认为一个非常天真的实现是在一开始就给两个1/2机会,然后根据过去的表现开始偏爱它们。这忽略了x,y,z,无论如何,请分享你的启发式,你的经验,如果有的话,你的提示。

示例代码:

代码语言:javascript
复制
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;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-11 12:48:47

我会删除计算机的专门化,在你的PLINQ代码上使用WithDegreeOfParallelism。如果你的决策器了解到没有并行是最优的,就让它返回1。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3020096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档