You must replace Microsoft PPL with PLINQ. The code uses combinable . I know for sure that there is an analogue in PLINQ.

    1 answer 1

    Looks like you need an Aggregate method. An example of using combinable , which combinable sum of prime numbers:

     combinable<int> sum; parallel_for_each(begin(a), end(a), [&](int i) { sum.local() += (is_prime(i) ? i : 0); }); prime_sum = sum.combine(plus<int>()); 

    Using Aggregate looks like this:

     var primeSum = a.AsParallel().Aggregate( // ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅ΠΌ Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ 0, // выполняСм суммированиС ΠΏΠ°Ρ€Π°Π»Π»Π΅Π»ΡŒΠ½ΠΎ (Π°Π½Π°Π»ΠΎΠ³ local()) (subtotal, item) => subtotal + (IsPrime(item) ? item : 0), // ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ ΠΎΠ±Ρ‰ΡƒΡŽ сумму (Π°Π½Π°Π»ΠΎΠ³ combine()) (total, subtotal) => total + subtotal, // ΠΎΡ‚Π΄Π°Π΅ΠΌ сумму Π±Π΅Π· ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ (final) => final); 
    • The person who gave me the assignment said that it was not an aggregate. those. through the aggregate, the same is possible and your answer is definitely true, but there is still something that β€œconsists of two words” (this is the only thing he remembered). - user3239600
    • @ user3239600 in principle, the same can be achieved using Parallel.ForEach . But what's the guessing game to play? - andreycha
    • @ user3239600: With us here, you see, usually help solve a programming problem, and not read the thoughts of another person. - VladD