سؤال

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.)

هل كانت مفيدة؟

المحلول

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).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top