Advertisement
overwater

Untitled

May 30th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. /* ... some libs and inits... */
  2.     /* .......Variables Initialisation ......*/
  3.     MPI_Status status;    
  4.     int n_size, NoofRows_Bloc, NoofRows, NoofCols;
  5.     int Numprocs, MyRank, Root = 0;
  6.     int irow, jrow, icol, index, ColofPivot, neigh_proc;
  7.  
  8.     double **Matrix_A, *Input_A, *Input_B, *ARecv, *BRecv;
  9.     double *Output, Pivot;
  10.  
  11.     double *X_buffer, *Y_buffer;
  12.     double *Buffer_Pivot, *Buffer_bksub;
  13.     double tmp;
  14.  
  15.     /* ........MPI Initialisation .......*/
  16.     MPI_Init(&argc, &argv);
  17.     MPI_Comm_rank(MPI_COMM_WORLD, &MyRank);
  18.     MPI_Comm_size(MPI_COMM_WORLD, &Numprocs);
  19.  
  20.     double time1;
  21.     /* .......Read the Input file ......*/
  22.     if(MyRank == 0) {
  23.  
  24.         srand(time(0));
  25.         NoofRows = 500;
  26.         NoofCols = 500;
  27.         n_size=NoofRows;
  28.  
  29.         /* ...Allocate memory and read data .....*/
  30.         Matrix_A = new double*[n_size];
  31.  
  32.         for(irow = 0; irow < n_size; irow++){
  33.             Matrix_A[irow] = new double[n_size];
  34.             for(icol = 0; icol < n_size; icol++)
  35.                 Matrix_A[irow][icol] = rand() % 10;
  36.         }
  37.  
  38.         Input_B  = new double[n_size];
  39.         for (irow = 0; irow<n_size; irow++)
  40.             Input_B[irow] = rand() % 10;
  41.  
  42.         /* ...Convert Matrix_A into 1-D array Input_A ......*/
  43.         Input_A  = new double[n_size * n_size];
  44.         index    = 0;
  45.         for(irow=0; irow<n_size; irow++)
  46.             for(icol=0; icol<n_size; icol++)
  47.                 Input_A[index++] = Matrix_A[irow][icol];
  48.  
  49.         time1 = realtime();
  50.  
  51.     }
  52.     MPI_Barrier(MPI_COMM_WORLD); // Waiting for all processes
  53.  
  54.  
  55.     MPI_Bcast(&NoofRows, 1, MPI_INT, Root, MPI_COMM_WORLD);
  56.     MPI_Bcast(&NoofCols, 1, MPI_INT, Root, MPI_COMM_WORLD);
  57.  
  58.  
  59.     /* .... Broad cast the size of the matrix to all ....*/
  60.     MPI_Bcast(&n_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
  61.  
  62.     NoofRows_Bloc = n_size/Numprocs;
  63.     /*......Memory of input matrix and vector on each process .....*/
  64.     ARecv = new double[NoofRows_Bloc * n_size];
  65.     BRecv = new double[NoofRows_Bloc];
  66.  
  67.     /*......Scatter the Input Data to all process ......*/
  68.     MPI_Scatter (Input_A, NoofRows_Bloc * n_size, MPI_DOUBLE, ARecv, NoofRows_Bloc * n_size,
  69.         MPI_DOUBLE, 0, MPI_COMM_WORLD);
  70.  
  71.     MPI_Scatter (Input_B, NoofRows_Bloc, MPI_DOUBLE, BRecv, NoofRows_Bloc, MPI_DOUBLE, 0,
  72.         MPI_COMM_WORLD);
  73. /* ... to be continued... */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement