Advertisement
SpandITime

MPI.c

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