Advertisement
Bernard0x01

Untitled

Apr 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5.  
  6. #define SIZE 1024 * 1024 * 32
  7. #define DEFAULT_TAG 100
  8.  
  9. static int array[SIZE];
  10.  
  11. int main(int argc, char** argv) {
  12.    int ierr;
  13.    ierr = MPI_Init(&argc, &argv);
  14.  
  15.    int currentProcessID;
  16.    int rootProcess = 0;
  17.    int worldSize;
  18.  
  19.    ierr = MPI_Comm_rank(MPI_COMM_WORLD, &currentProcessID);
  20.    ierr = MPI_Comm_size(MPI_COMM_WORLD, &worldSize);
  21.  
  22.    MPI_Request requests[2];
  23.    MPI_Status stats[2];
  24.  
  25.    int startSize = 1;
  26.    int part = 1024 * 7 + 999;// 1024 * 7;
  27.  
  28.    if (currentProcessID == 0) {
  29.        MPI_Isend(
  30.                &array[0],
  31.                part,
  32.                MPI_INT,
  33.                1,
  34.                DEFAULT_TAG,
  35.                MPI_COMM_WORLD,
  36.                &requests[0]
  37.        );
  38.    } else {
  39.        clock_t start, end, end2;
  40.        start = clock();
  41.        MPI_Irecv(
  42.                &array[0],
  43.                part,
  44.                MPI_INT,
  45.                0,
  46.                DEFAULT_TAG,
  47.                MPI_COMM_WORLD,
  48.                &requests[1]
  49.        );
  50.        MPI_Wait(&requests[1], &stats[1]);
  51.        end = clock();
  52.        printf("Time need to call isend(size = %d bytes) is %f sec \n",
  53.               part * sizeof(int),
  54.               ((double) (end - start)) / CLOCKS_PER_SEC
  55.        );
  56.    }
  57.  
  58.    return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement