Here is the serial for loop to find the primes from 2 to 100000:
And here is its output:
Note down the Thread ID, and it took 24511 milliseconds. And here is its equivalent Parallel code:
Here comes the output:
This program determines prime number in a big range of 100000 numbers. But if you replace the both programs for less numbers, say 5000, or 10000, then the serial for loop will be more efficient. Because, Task objects creation incurs overhead and exceeds the solution time. So, if your problem is small try to avoid parallelize your code.
No comments:
Post a Comment