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);
- MPI_Request req;
- int rank, size, length, test;
- int new_rank;
- int element = 0;
- int n = 4;
- int m = 4;
- MPI_Status status;
- 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];
- int final[n][m];
- MPI_Comm new_comm;
- int pom[3];
- int pom2[3];
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- int pom3[size][3];
- element = rank;
- cout << "Proces P[" << rank << "]. Jego elemnt to = " << element << endl;
- MPI_Cart_create(MPI_COMM_WORLD, 2, dim, periods, reorder, &new_comm);
- MPI_Cart_coords(new_comm, rank, 2, coord);
- cout << "Proces P[" << rank << "]. Wspolrzędne["<<coord[0]<<"]["<<coord[1]<<"]"<< endl;
- int pom4[size][3];
- // cout<<"rank "<<i<<" wyslal swoj elelemt";
- MPI_Cart_coords(new_comm, rank, 2, coord);
- pom3[rank][0]= element;
- pom3[rank][1]=coord[0];
- pom3[rank][2]=coord[1];
- cout<<"rank "<<rank<<"/c1/c2|"<<pom3[rank][0]<<"/"<<pom3[rank][1]<<"/"<<pom3[rank][2]<<endl;
- MPI_Reduce(&pom3, &pom4, size*3, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
- if(rank==0){
- for(int i =0; i < size; i++)
- {
- cout<<"m"<<i;
- cout<<"/"<<pom4[i][0]<<"/"<<pom4[i][1]<<"/"<<pom4[i][2]<<endl;
- }
- }
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement