Sunteți pe pagina 1din 6

#include <mpi.

h>
#include <stdio.h>

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


MPI_Init(&argc,&argv);
printf("Hello World\n");
MPI_Finalize();
return 0;
}
#include <mpi.h>
#include <stdio.h>

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


int a=2,b=3;
// printf("Enter numbers: \n");
// scanf("%d,%d",&a,&b);
int rank;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
switch(rank){
case 0: printf("For processor %d a+b %d\n",rank,a+b);
break;
case 1: printf("For processor %d a-b %d\n",rank,a-b);
break;
case 2: printf("For processor %d a*b %d\n",rank,a*b);
break;
case 3: printf("For processor %d a/b %d\n",rank,a/b);
}
MPI_Finalize();
return 0;
}
#include <mpi.h>
#include <stdio.h>

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

int rank;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
if (rank%2)
printf("%d --> World\n",rank);
else
printf("%d --> Hello\n",rank);
MPI_Finalize();
return 0;
}
#include <mpi.h>
#include <stdio.h>
//#include <math.h>

int isPrime(int x)
{
if (x<2)
return 0;
if (x==2||x==3)
return 1;
int n = x/2;
int i;
for(i=2;i<=n;i++)
if (x%i==0)
return 0;
return 1;
}

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

int rank,i;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);

for (i=rank*50+1;i<=50*(rank+1);i++){
// printf("Processor %d says %d is ",rank,i);
// if(isPrime(i))
// printf("prime\n");
// else
// printf("not prime\n");
if(isPrime(i))
printf("%d: %d\n",rank,i);
}

MPI_Finalize();
return 0;
}
#include <mpi.h>
#include <stdio.h>

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


int rank,size;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
if(rank==0)
printf("Hello world from process %d",rank);
MPI_Finalize();
return 0;
}
#include <mpi.h>
#include <stdio.h>

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

int rank;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
int a[6]={1,2,3,4,5,6};
int b[6]={1,1,1,1,1,1};
int c[6]={};

int i;

for(i=rank*3+0;i<(rank+1)*3;i++){
c[i]=a[i]+b[i];
printf("%d: c[%d]=%d\n",rank,i,c[i]);
}

MPI_Finalize();
return 0;
}