Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: Abort a suspended thread Pin
Fahad Sadah25-May-09 2:07
Fahad Sadah25-May-09 2:07 
AnswerRe: Abort a suspended thread Pin
Fahad Sadah25-May-09 2:05
Fahad Sadah25-May-09 2:05 
QuestionDelegates and Parallel.For Pin
Fahad Sadah25-May-09 1:25
Fahad Sadah25-May-09 1:25 
AnswerRe: Delegates and Parallel.For Pin
S. Senthil Kumar25-May-09 3:38
S. Senthil Kumar25-May-09 3:38 
GeneralRe: Delegates and Parallel.For Pin
harold aptroot25-May-09 3:39
harold aptroot25-May-09 3:39 
GeneralRe: Delegates and Parallel.For Pin
S. Senthil Kumar25-May-09 3:52
S. Senthil Kumar25-May-09 3:52 
GeneralRe: Delegates and Parallel.For Pin
Fahad Sadah25-May-09 7:26
Fahad Sadah25-May-09 7:26 
AnswerRe: Delegates and Parallel.For Pin
Nicholas Butler25-May-09 7:54
sitebuilderNicholas Butler25-May-09 7:54 
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 Smile | :)

QuestionSlide bar Pin
yesu prakash25-May-09 1:18
yesu prakash25-May-09 1:18 
AnswerRe: Slide bar Pin
Eduard Keilholz25-May-09 3:37
Eduard Keilholz25-May-09 3:37 
QuestionAccessing the right Registry entry for Internet Explorer in C# Pin
ramz_g25-May-09 1:05
ramz_g25-May-09 1:05 
AnswerRe: Accessing the right Registry entry for Internet Explorer in C# Pin
Rajesh R Subramanian25-May-09 4:03
professionalRajesh R Subramanian25-May-09 4:03 
QuestionXmlTextWriter and MemoryStream Pin
OriginalGriff25-May-09 1:05
mveOriginalGriff25-May-09 1:05 
Question7.1 Surround Sound Pin
Chris MacEwan25-May-09 0:51
Chris MacEwan25-May-09 0:51 
AnswerRe: 7.1 Surround Sound Pin
molesworth25-May-09 2:18
molesworth25-May-09 2:18 
Questionopen aspx page Pin
michaelgr125-May-09 0:50
michaelgr125-May-09 0:50 
AnswerRe: open aspx page Pin
padmanabhan N25-May-09 1:31
padmanabhan N25-May-09 1:31 
GeneralRe: open aspx page Pin
michaelgr125-May-09 1:32
michaelgr125-May-09 1:32 
AnswerRe: open aspx page Pin
Ramesh Swaminathan25-May-09 3:22
Ramesh Swaminathan25-May-09 3:22 
AnswerRe: open aspx page Pin
Vasudevan Deepak Kumar25-May-09 3:51
Vasudevan Deepak Kumar25-May-09 3:51 
QuestionWrong COM Port Number Pin
stancrm25-May-09 0:04
stancrm25-May-09 0:04 
AnswerRe: Wrong COM Port Number Pin
Moreno Airoldi25-May-09 3:56
Moreno Airoldi25-May-09 3:56 
GeneralRe: Wrong COM Port Number Pin
Rajesh Anuhya25-May-09 3:58
professionalRajesh Anuhya25-May-09 3:58 
GeneralRe: Wrong COM Port Number Pin
Dave Kreskowiak25-May-09 6:59
mveDave Kreskowiak25-May-09 6:59 
AnswerRe: Wrong COM Port Number Pin
Rajesh Anuhya25-May-09 3:56
professionalRajesh Anuhya25-May-09 3:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.