Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include "cmath"
  2. #include "iostream"
  3. #include "ctime"
  4. #include "iomanip"
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "mpi.h"
  8.  
  9. #define MASTER 0
  10. using namespace std;
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.     MPI_Init(&argc, &argv);
  15.     MPI_Request req;
  16.     int rank, size, length, test;
  17.     int new_rank;
  18.     int element = 0;
  19.     int n = 4;
  20.     int m = 4;
  21.  
  22.     MPI_Status status;
  23.  
  24.     int *dim = new int[2];
  25.     int *periods = new int[2];
  26.     int *coord = new int[2];
  27.     int reorder;
  28.     dim[0] = n;
  29.     dim[1] = m;
  30.     periods[0] = false;
  31.     periods[1] = false;
  32.     reorder = true;
  33.     int tab[n][m];
  34.     int final[n][m];
  35.     MPI_Comm new_comm;
  36.     int pom[3];
  37.     int pom2[3];
  38.    
  39.  
  40.     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  41.     MPI_Comm_size(MPI_COMM_WORLD, &size);
  42.     int pom3[size][3];
  43.     element = rank;
  44.    
  45.     cout << "Proces P[" << rank << "]. Jego elemnt to = " << element << endl;
  46.  
  47.     MPI_Cart_create(MPI_COMM_WORLD, 2, dim, periods, reorder, &new_comm);
  48.    
  49.     MPI_Cart_coords(new_comm, rank, 2, coord);
  50.     cout << "Proces P[" << rank << "]. Wspolrzędne["<<coord[0]<<"]["<<coord[1]<<"]"<< endl;
  51.  
  52.     int pom4[size][3];
  53.  
  54.    
  55.     //  cout<<"rank "<<i<<" wyslal swoj elelemt";
  56.         MPI_Cart_coords(new_comm, rank, 2, coord);
  57.             pom3[rank][0]= element;
  58.             pom3[rank][1]=coord[0];
  59.             pom3[rank][2]=coord[1];
  60.            
  61.              cout<<"rank "<<rank<<"/c1/c2|"<<pom3[rank][0]<<"/"<<pom3[rank][1]<<"/"<<pom3[rank][2]<<endl;
  62.  
  63.        
  64.  
  65.    
  66.        
  67.  
  68.     MPI_Reduce(&pom3, &pom4, size*3, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  69.  
  70. if(rank==0){
  71.  
  72. for(int i =0; i < size; i++)
  73. {  
  74.                 cout<<"m"<<i;
  75.                 cout<<"/"<<pom4[i][0]<<"/"<<pom4[i][1]<<"/"<<pom4[i][2]<<endl;
  76.        
  77.         }
  78. }
  79.     MPI_Finalize();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement