Advertisement
alexdmin

lab2.1

Sep 30th, 2022
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char** argv)
  8. {
  9.     int myid, n = 2, *rbuf = 0, *sbuf = 0 ;
  10.     int size;
  11.     MPI_Comm comm = MPI_COMM_WORLD;
  12.     MPI_Init(&argc, &argv);
  13.     MPI_Comm_size(comm, &size);
  14.     MPI_Comm_rank(comm, &myid);
  15.  
  16.     sbuf = new int [size * n];
  17.     rbuf = new int [size * n];
  18.    
  19.     for(int i = 0; i < size * n; i++)
  20.     {
  21.         sbuf[i] = myid;
  22.     }
  23.     cout << "Process " << myid << " | ";
  24.    
  25.     for(int i = 0; i < size * n; i++)
  26.         cout << "  " << sbuf[i];
  27.    
  28.     MPI_Alltoall(sbuf, n, MPI_INT, rbuf, n, MPI_INT, comm);
  29.    
  30.     cout << "       " << "Process " << myid << " | ";
  31.     for(int i = 0; i < size * n; i++)
  32.         cout << "  " << rbuf[i];
  33.     cout << endl;
  34.  
  35.     MPI_Finalize();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement