Good question! The problem you have is that you don't know the bounds of your input - you don't know how big number will have to get to generate the required number of primes. However, you can still parellelise chunks of work - something like this:
const int N = ( int ) 1e6;
static readonly int STEP = Environment.ProcessorCount * ( int ) 1e6;
...
var primes = new List<int>( N );
for ( int start = 2 ; primes.Count < N ; start += STEP )
primes.AddRange(
Enumerable.Range( start, STEP )
.AsParallel().AsOrdered()
.Where( i => IsPrime( i ) ) );
primes = primes.Take( N ).ToList();
You'll have to tune the values of N and STEP for your specific case. Nick
---------------------------------- Be excellent to each other :)
mea culpa. As someone else said, it's at the bottom of the home page, but also at: http://www.codeproject.com/#\_poll (which, now that I mention it, is just an anchor on the home page, so I'll just slink away now)
-------------- TTFN - Kent
Purely in the interests of research, you understand, I viewed one of the related videos. I got a person of the female persuasion stroking her pussy. It was a lovely grey and white one with the longest whiskers and a very loud meoooooooooooow. Is this what counts as porn, or was I really unlucky?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?"
The 'last' one could have been worse... Imagine that ALL the machines had the 'new last' taking precendence over the system last. Power to all the machines would have to have been cut. Also, I like:
10 Preheat oven to 350
20 Combine all ingredients in a large mixing bowl
30 Mix until smooth
Change it in the project properties, it can dictate which folder the files are stored in, and you can set where you want the compiler to output the debug and exe files
Ok Thank you very much for bringing this aspect to my attention. It was quite a nice learning experience for me. Thanks !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
Dave Kreskowiak wrote:
save yourself that hassle of trying to "force" the thing to work
Kind of like pounding a square peg through a round hole :->
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
Do what any of us are going to do. Google for "VB.NET IRC Client".
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007