Codehaks
Codehaks

Reputation: 338

How many parallel process can I run?

I have a corei7 processor with 8 logical processors.

I'm trying to run a parallel task in dotnet core 2.2 using parallel.For. when I measure start time there are 9 tasks started in parallel. Isn't it suppose to be just 8?

below you can see :

i => [ThreadId],[ProcessorNumber] == starttime - endtime

enter image description here

Parallel tasks result

Upvotes: 8

Views: 5621

Answers (1)

Karl Johan Vallner
Karl Johan Vallner

Reputation: 4300

You can run however many tasks in parallel that you want, but the processor only has 8 logical cores to process 8 threads simultaneously. The rest will always queue up and wait their turn.

So if you have 16 parallel processes, which each take 200ms to run, then you will run process 1-8 in parallel for 200ms, then 9-16 in parallel for 200ms, totalling at 400ms. If you had 4 logical cores, you would run process 1-4, 5-8, 9-12, 13-16 in parallel, totalling in at 800ms.

Upvotes: 8

Related Questions