Want more on PLINQ? Leave a message. Source code available at: github.com/JasperKent/Parallelization Remember to subscribe at th-cam.com/channels/qWQzlUDdllnLmtgfSgYTCA.html And if you liked the video, click the 👍.
Parallel.ForEach(values, (value, _) => { results[value] = Factoriel(value % 20 + 1); usage.AddOrUpdate(Environment.CurrentManagedThreadId, 1, (_, count) => count + 1); } ); is working fine (value is the index) i didn't understand why you introduced the concurentBag collection for this loop
The 'results' array has to be pre-allocated to the number of results, which in this case, we happen to know. In other circumstances, we might not know the final size, and if we want the collection to expand to fit, it has to be thread safe.
The parellisation of the average() method doesn't give the same result : with parallelisation the result is 228150401,23158336 without parallelisation the method the result is 228150401,3512809.So an error is introduced
I think that's related to the rounding errors one can get with doubles. Without parallelization, the rounding error is consistent, whereas with parallelization there is a degree of randomization, but neither is correct. If you do this with decimals instead of doubles, you consistently get the result 228,150,401.25. This is because the decimal type is explicitly designed to avoid rounding errors. We can verify this is the correct result by looking at the Sum() and Count() of the results, which are: 114,075,200,625,000,000 500,000,000 Cancelling the zeros gives: 114,075,200,625 500 I'm not going to do the full long division, but it's evident this ends in exactly .25.
@@CodingTutorialsAreGo Yes it is related the rounding errors one can get with doubles . If you chunk the list depending on the chunks and their order you wont get nécessarily the exact same result . Thank you
Hey great video man! I would only love to ask something in addition, is it SOMEHOW possible to use "Paralell.ForEach(..)" with the newly added "RegexSrcGenerator" so because when i do this code here: Paralell.ForEach(regex.EnumerateMatches(mySpan), (match, _) => { //error cant do that because of it returning an "ValueMatchEnumerator".... });
Want more on PLINQ? Leave a message.
Source code available at: github.com/JasperKent/Parallelization
Remember to subscribe at th-cam.com/channels/qWQzlUDdllnLmtgfSgYTCA.html
And if you liked the video, click the 👍.
Could you please make a video of Task vs thread
@@finwwwfinwww4669 I'll put it on the list.
Thank you very much for adding subtitles! It's very helpful for non-native speakers💛
Happy Friday Sir! Fair and simple into.
Good explanation, would be interesting if you went further into performance, as the overhead from Parallel can make it perform slower in many cases.
Parallel.ForEach(values, (value, _) =>
{
results[value] = Factoriel(value % 20 + 1);
usage.AddOrUpdate(Environment.CurrentManagedThreadId, 1, (_, count) => count + 1);
}
);
is working fine (value is the index) i didn't understand why you introduced the concurentBag collection for this loop
The 'results' array has to be pre-allocated to the number of results, which in this case, we happen to know. In other circumstances, we might not know the final size, and if we want the collection to expand to fit, it has to be thread safe.
@@CodingTutorialsAreGo clear thank you
Great explanation!
The parellisation of the average() method doesn't give the same result : with parallelisation the result is 228150401,23158336 without parallelisation the method the result is 228150401,3512809.So an error is introduced
I think that's related to the rounding errors one can get with doubles. Without parallelization, the rounding error is consistent, whereas with parallelization there is a degree of randomization, but neither is correct.
If you do this with decimals instead of doubles, you consistently get the result 228,150,401.25. This is because the decimal type is explicitly designed to avoid rounding errors.
We can verify this is the correct result by looking at the Sum() and Count() of the results, which are:
114,075,200,625,000,000
500,000,000
Cancelling the zeros gives:
114,075,200,625
500
I'm not going to do the full long division, but it's evident this ends in exactly .25.
@@CodingTutorialsAreGo Yes it is related the rounding errors one can get with doubles . If you chunk the list depending on the chunks and their order you wont get nécessarily the exact same result . Thank you
thanks for the guide.
Another Friday made better with a Coding Tutorials tutorial.
very nice!
hard. The soft soft interface is quite friendly
What?
Hey great video man! I would only love to ask something in addition, is it SOMEHOW possible to use "Paralell.ForEach(..)" with the newly added "RegexSrcGenerator" so because when i do this code here:
Paralell.ForEach(regex.EnumerateMatches(mySpan), (match, _) =>
{
//error cant do that because of it returning an "ValueMatchEnumerator"....
});
Not something I know off the top of my head. I'll take a look if I have time.
@@CodingTutorialsAreGo thx brother! have a good time