How to solve using PLINQ and LINQ at runtime?

Or decide between parallel and sequential operation as a whole. It is difficult to find out without checking if parallel or sequential implementation is better due to overhead. Obviously, it will take some time to train the "decider" which method to use. I would say that this method cannot be perfect, therefore it is probabilistic in nature. x,y,zreally affect the decisive. I think a very naive implementation will be to give as a 1/2chance at the beginning, and then start approving them in accordance with past work. It ignores x,y,z. In any case, please share your heuristics, your experience, if any, your advice on this issue.

Code example:

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;
    }
}
+3
1

WithDegreeOfParallelism PLINQ. 1, , parallelism.

+1

Source: https://habr.com/ru/post/1749517/


All Articles