tag:blogger.com,1999:blog-913600556879440043.post7030455532468841271..comments2024-03-28T14:53:38.243+05:30Comments on Computer Revolution (www.comrevo.com): OPENMP program to find prime numbers from range 1 to n by parallel processing (multi-threading)Parag Jambhulkarhttp://www.blogger.com/profile/13991750622483538113noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-913600556879440043.post-25420441073842627172017-11-06T18:53:36.210+05:302017-11-06T18:53:36.210+05:30Nice logic..Nice logic..Anonymoushttps://www.blogger.com/profile/06376534748993172414noreply@blogger.comtag:blogger.com,1999:blog-913600556879440043.post-41425190278431117082016-12-14T12:15:39.046+05:302016-12-14T12:15:39.046+05:30Yes, for sure.Yes, for sure.Parag Jambhulkarhttps://www.blogger.com/profile/13991750622483538113noreply@blogger.comtag:blogger.com,1999:blog-913600556879440043.post-80766764479166537032016-12-14T11:34:34.459+05:302016-12-14T11:34:34.459+05:30is it parallel enough ?is it parallel enough ?Anonymoushttps://www.blogger.com/profile/02509076093637321579noreply@blogger.comtag:blogger.com,1999:blog-913600556879440043.post-11319019393597673072016-03-05T19:11:53.698+05:302016-03-05T19:11:53.698+05:30I will illustrate your query with an example:
Sup...I will illustrate your query with an example:<br /><br />Suppose we have to find out prime numbers from 1 to 20.<br />Then,<br /><br />1. Neglect 1 as it is nor prime nor composite. That means we have to find out prime numbers from 2 to 20.<br /><br />2. We will start with 2 and will remove all multiples of 2 i.e. 2*2, 2*3, 2*4, 2*5......<br /><br />3. Next, we have to remove all multiples of 3 i.e. 3*2, 3*3, 3*4, 3*5....<br /> Here unnecessarily we are looking for 3*2 as we have already seen 2*3 (in step 2).<br /><br />4. Next, we will remove all multiples of 4 i.e. 4*2, 4*3, 4*4, 4*5....<br /> Here unnecessarily we are looking for 4*2 and 4*3 as we have already remove 2*4(in step 2) and 3*4(in step 3).<br /><br />5. I generalize this; suppose you want to remove multiples of i i.e. i*2, i*3, i*4....Here if i=4 then no need to check for i*2 and i*3 as already those cases are considered. Better to start with i*i. That's why the loop for(j=i*i;j<=n;j=j+i).<br /><br />6. You may also wonder why outer loop for(i=2;i*i<=n;i++).<br />Now see, we are removing multiples starting from i*i as mentioned in inner loop. If i*i is greater than n, then there is no point to consider i as we have to find prime numbers from 1 to n.<br /><br />7. Try any example like 1 to 20. you will be understood in more better way. <br /><br />Thanks a lot for your comment.Parag Jambhulkarhttps://www.blogger.com/profile/13991750622483538113noreply@blogger.comtag:blogger.com,1999:blog-913600556879440043.post-56698565282994829532016-03-03T17:13:38.369+05:302016-03-03T17:13:38.369+05:30Can you please explain cannot understand the code....Can you please explain cannot understand the code. what does "i*i is less than 'n' to avoid repetition." mean? and why do we use the loop "for(j=i*i;j<=n;j=j+i)"?Programmerhttps://www.blogger.com/profile/08017672992349757115noreply@blogger.com