0% found this document useful (0 votes)
56 views

Paralleization of Prime Numbers Using MPI

This document contains an MPI program that parallelizes finding prime numbers between 2 and a user-input value n. The program initializes MPI, gets the process rank and total processes, then has each process check all numbers in its range to see if they are divisible by any numbers between 2 and the square root of the number, printing any primes it finds before finalizing MPI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Paralleization of Prime Numbers Using MPI

This document contains an MPI program that parallelizes finding prime numbers between 2 and a user-input value n. The program initializes MPI, gets the process rank and total processes, then has each process check all numbers in its range to see if they are divisible by any numbers between 2 and the square root of the number, printing any primes it finds before finalizing MPI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMENT

D.SAI ANIRUDH
17MIS7072
Parallelization of Prime Numbers using MPI
#include <stdio.h>
#include "mpi.h"

int main(int argc, char* argv[])


{
int rank, size, len;
char version[MPI_MAX_LIBRARY_VERSION_STRING];

MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Get_library_version(version, &len);
/* printf("Hello, world, I am %d of %d, (%s, %d)\n",
rank, size, version, len); */
int n;
//enter maxi.
scanf("%d",&n);
int f=0;
for(int i=2;i<n;i++)
{
f=0;
for(int j=2;j<=i/2;j++)
{
if(i%j==0)
{f=1;}
}
if(f==0)
{
printf("%d\n",i);
}
}
MPI_Finalize();
return 0;
}

Output

You might also like