Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

ParallelDo and Do results don't match

Posted 2 years ago

Hello, I am asking for a hint.
For example, I have a list of random natural numbers:

t = Table[RandomInteger[{1, 10000}], {10^7}];

I want to count how many prime numbers there are:

howmany = 0;
Do[ If[ PrimeQ[ t[[i]] ], howmany++], {i, 10^7}]

and now the same but using parallel computation:

howmany = 0; 
ParallelDo[ If[ PrimeQ[ t[[i]] ], howmany++], {i, 10^7}]

Unfortunately, the second result is incorrect. My guess is that because there is a problem with accessing vvv at the same time.
Is there any simple solution to this problem? E.g. Each thread has its cold number, and then at the end you can sum them up?

Pozdrawiam
M

POSTED BY: M P
2 Replies
Posted 2 years ago
POSTED BY: Eric Rimbey

You can try Parallelize[Count[list,pattern]]

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard