Advertisement
SpandITime

Untitled

May 26th, 2022
613
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <mpi.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char* argv[]){
  5.     MPI_Init(&argc, &argv);
  6.     int id, np;
  7.     MPI_Comm_size(MPI_COMM_WORLD, &np);
  8.     MPI_Comm_rank(MPI_COMM_WORLD, &id);
  9.     double a = np / 10.;
  10.     double sum;
  11.     MPI_Reduce(&a,&sum,1,MPI_DOUBLE,MPI_SUM,np-1,MPI_COMM_WORLD);
  12.     printf("id = %d, a = %f\n", id, a);
  13.     if(id == np-1){
  14.         printf("id = %d, sum = %f\n", id, sum);
  15.     }
  16.     MPI_Finalize();
  17.     return 0;
  18. }
  19.  
Advertisement
RAW Paste Data Copied
Advertisement