Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cmath"
- #include "iostream"
- #include "ctime"
- #include "iomanip"
- #include "stdio.h"
- #include "stdlib.h"
- #include "mpi.h"
- #define MASTER 0
- using namespace std;
- int main(int argc, char **argv)
- {
- MPI_Init(&argc, &argv);
- int rank, size, length, test;
- int new_rank;
- double suma_col = 0;
- double suma_row = 0;
- double element = 0;
- int n = 4;
- int m = 4;
- int *dim = new int[2];
- int *periods = new int[2];
- int *coord = new int[2];
- int reorder;
- dim[0] = n;
- dim[1] = m;
- periods[0] = false;
- periods[1] = false;
- reorder = true;
- int tab[n][m];
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- if (rank == MASTER) {
- cout << "Master rozpoczyna prace. Liczba procesow = " << size << endl;
- //Tablica TAB
- cout << "Wypelniona Tablica TAB" << endl;
- srand(time(NULL));
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++) //wpisanie wartosci do tablicy
- {
- tab[i][j] = rand() % 11;
- cout << tab[i][j] << " ";
- }
- cout << endl;
- }
- }
- MPI_Scatter(tab, 1, MPI_INT, &element, 1, MPI_INT, MASTER, MPI_COMM_WORLD);
- cout << "Proces P[" << rank << "]. Odebrany Kawalek macierzy = " << element << endl;
- MPI_Cart_create(MPI_COMM_WORLD, 2, dim, periods, reorder, &new_comm);
- MPI_Cart_coords(comm, rank, 2, coord);
- cout << "Proces P[" << rank << "]. Wspolrzędne["<<coords[0]<<"]["<<coords[1]<<"]"<< endl;
- int u;
- int d;
- int r;
- int l;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- int k = i+1;
- int l = j+1;
- while(k<n && l<m){
- //w tych łajlach pobrac cart_ranki
- //sendnac
- //recivnac
- k++;
- l++;
- }
- k = i - 1;
- l = j - 1;
- while(k>=0 && l>=0){
- k--;
- l--;
- }
- k = i + 1;
- l = j - 1;
- while(k<n && l>=0){
- k++;
- l--;
- }
- k = i - 1;
- l = j + 1;
- while(l<m && k>=0){
- k--;
- l++;
- }
- }
- }
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement