Slide 17
Slide 17 text
Example: Finding Primes
// Initialize MPI and assume comm_size is 5
// Get the rank of the process
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for (int i = rank*2,000,000; i < (rank+1)*2,000,000; i++)
{
if(isPrime(i) == 1)
{
// Store i in a file
}
}
rank rank*2,000,000 (rank+1)*2,000,000
0 0 2,000,000
1 2,000,000 4,000,000
2 4,000,000 6,000,000
3 6,000,000 8,000,000
4 8,000,000 10,000,000