Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. #define comm MPI_COMM_WORLD
  4.  
  5. int main(int arge, char **argv)
  6. {
  7. MPI_Status status;
  8. MPI_Init(&arge,&argv);
  9. int N = 12;
  10. int ai, rank, size, del, i0, imax, i, s=0, s1=0;
  11.  
  12. MPI_Request request;
  13.  
  14. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  15. MPI_Comm_size(MPI_COMM_WORLD, &size);
  16.  
  17. int a[N];
  18.  
  19. del = N/size;
  20. i0 = rank*del;
  21. ai = i+1;
  22. imax = i0 + del;
  23. if (rank = size - 1)
  24. {
  25. imax = N;
  26. }
  27. for (i=i0;i<imax;i++)
  28. {
  29. a[i] =i+1;
  30. s1+=a[i];
  31. }
  32.  
  33. MPI_Reduce(&s1, &s, 1, MPI_INT, MPI_SUM, 0, comm);
  34. printf("rank=%d\n, size=%d\n, i0=%d\n, imax=%d\n, s1=%d\n, s=%d\n, a[i0]=%d\n", rank, size,i0,imax,s1,s,a[i0]);
  35. printf("Сумма составила: %i", s);
  36.  
  37.  
  38. MPI_Finalize();
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement