Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1.  
  2. #include "cmath"
  3. #include "iostream"
  4. #include "ctime"
  5. #include "iomanip"
  6. #include "stdio.h"
  7. #include "stdlib.h"
  8. #include "mpi.h"
  9.  
  10. #define MASTER 0
  11. using namespace std;
  12.  
  13. int main(int argc, char **argv)
  14. {
  15.     MPI_Init(&argc, &argv);
  16.     int rank, size, length, test;
  17.     int new_rank;
  18.     double suma_col = 0;
  19.     double suma_row = 0;
  20.     double element = 0;
  21.     int n = 4;
  22.     int m = 4;
  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.  
  35.     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  36.     MPI_Comm_size(MPI_COMM_WORLD, &size);
  37.    
  38.     if (rank == MASTER) {
  39.         cout << "Master rozpoczyna prace. Liczba procesow = " << size << endl;
  40.         //Tablica TAB
  41.         cout << "Wypelniona Tablica TAB" << endl;
  42.         srand(time(NULL));
  43.         for (int i = 0; i < n; i++)
  44.         {
  45.             for (int j = 0; j < m; j++) //wpisanie wartosci do tablicy
  46.             {
  47.                 tab[i][j] = rand() % 11;
  48.                 cout << tab[i][j] << " ";
  49.             }
  50.             cout << endl;
  51.         }
  52.     }
  53.    
  54.    
  55.     MPI_Scatter(tab, 1, MPI_INT, &element, 1, MPI_INT, MASTER, MPI_COMM_WORLD);
  56.     cout << "Proces P[" << rank << "]. Odebrany Kawalek macierzy = " << element << endl;
  57.  
  58.     MPI_Cart_create(MPI_COMM_WORLD, 2, dim, periods, reorder, &new_comm);
  59.    
  60.     MPI_Cart_coords(comm, rank, 2, coord);
  61.     cout << "Proces P[" << rank << "]. Wspolrzędne["<<coords[0]<<"]["<<coords[1]<<"]"<< endl;
  62.    
  63.     int u;
  64.     int d;
  65.     int r;
  66.     int l;
  67.    
  68.     for(int i = 0; i < n; i++){
  69.         for(int j = 0; j < m; j++){
  70.                
  71.                 int k = i+1;
  72.                 int l = j+1;
  73.             while(k<n && l<m){
  74.                 //w tych łajlach pobrac cart_ranki
  75.                 //sendnac
  76.                 //recivnac
  77.                 k++;
  78.                 l++;
  79.             }
  80.            
  81.             k = i - 1;
  82.             l = j - 1;
  83.             while(k>=0 && l>=0){
  84.        
  85.                 k--;
  86.                 l--;
  87.             }
  88.            
  89.             k = i + 1;
  90.             l = j - 1;
  91.             while(k<n && l>=0){
  92.                
  93.                 k++;
  94.                 l--;
  95.            
  96.             }
  97.            
  98.             k = i - 1;
  99.             l = j + 1;
  100.             while(l<m && k>=0){
  101.            
  102.                 k--;
  103.                 l++;
  104.            
  105.             }
  106.         }
  107.     }
  108.  
  109.    
  110.    
  111.        
  112.     MPI_Finalize();
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement