Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plinq inside Plinq?

Let's say I have a DataTable.

var dt = getDataTable();

and then I do

Parallel.For (0, dt.Rows.Count, i => Foo (dt.Rows[i]));

Foo is a function which do some calculations on a row.

Should Foo also use Plinq ? or Should not ?

( it doesn't make sense to divide into cores after already divided.)

like image 789
Royi Namir Avatar asked Dec 14 '25 17:12

Royi Namir


1 Answers

Should Foo also use Plinq ? or Should not ?

In general, you typically only want to parallelize at the "highest level" possible. By making larger work items, you maximize the total throughput, since you're reducing the amount of overhead required to schedule the work.

If you used PLINQ inside of a Parallel.For loop, you'd be adding overhead (in order to schedule the work items), but not being able to take advantage of more cores, so you'll likely reduce your overall performance. As such, I would not recommend using PLINQ inside of Foo in this case (provided the DataTable has enough rows to parallelize nicely).

like image 177
Reed Copsey Avatar answered Dec 17 '25 08:12

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!