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.)
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.Forloop, 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 ofFooin this case (provided theDataTablehas enough rows to parallelize nicely).