q explain use of mpi functions with an


Q. Explain use of MPI functions with an example?

include

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

int i, tmp, sum, s, r, N, x[100];

MPI_Init(&argc, &argv);

MPI_Comm_size(MPI_COMM_WORLD, &s);

MPI_Comm_rank(MPI_COMM_WORLD, &r);

If(r==0)

 {

  printf( "Enter N:");

  scanf ("%d", &N);

  for (i=1; i

     MPI_Send(&N, 1, MPI_INT,i, i, MPI_COMM_WORLD);

  for (i=r, i

     sum+= x[i];  

 for (i=r, i

 {

   MPI_Recv(&tmp, 1, MPI_INT,i, i,  MPI_COMM_WORLD, &status);

   Sum+=tmp;

}

printf( "%d", sum);

}

else {

          MPI_Recv(&N, 1, MPI_INT,0, i, MPI_COMM_WORLD, &status);

          for (i=r, i

                sum+= x[i];  

          MPI_Send(&sum, 1, MPI_INT, 0, i, MPI_COMM_WORLD);

}

MPI_Finalize( );

}

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: q explain use of mpi functions with an
Reference No:- TGS0313220

Expected delivery within 24 Hours