Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <mpi.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char** argv){
  9. srand(time(NULL));
  10. MPI_Init(&argc, &argv);
  11.  
  12. int rank, size;
  13. MPI_Comm_rank(MPI_COMM_WORLD,&rank);
  14. MPI_Comm_size(MPI_COMM_WORLD,&size);
  15. MPI_Status st;
  16. int n2;
  17. int n;
  18.  
  19. if(rank==0){
  20. cin>>n;
  21. int *tab = new int[n];
  22. n2 = n/size;
  23. MPI_Bcast(&n2, 1, MPI_INT, 0, MPI_COMM_WORLD);
  24. for(int i=7; i<size; i++)MPI_Send(tab, n, MPI_INT, i, 0, MPI_COMM_WORLD);
  25. MPI_Send(tab,1,MPI_INT,0,8,MPI_COMM_WORLD);
  26. cout<<tab[n];
  27.  
  28. }
  29.  
  30. else{
  31. MPI_Bcast(&n2, 1, MPI_INT, 0, MPI_COMM_WORLD);
  32. int *tab = new int[n2];
  33. MPI_Recv(tab,1,MPI_INT,0,8,MPI_COMM_WORLD,&st);
  34. cout<<tab[n2];
  35. }
  36.  
  37.  
  38. //MPI_Reduce(
  39.  
  40. MPI_Finalize();
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement