#include printf(“Running with num_elements : %d “, N); printf(“Running

#include #include #include #include void merge(int *, int *, int, int, int);void mergeSort(int *, int *, int, int);#define N 80000000UL#define BASE_SEED 0x1234abcdint main(int argc, char** argv) {  // Start MPI  int rank;  int size;  double start, end;  MPI_Init(&argc, &argv);  MPI_Comm_rank(MPI_COMM_WORLD, &rank);  MPI_Comm_size(MPI_COMM_WORLD, &size);  printf(“Running with num_elements : %d
“, N);  printf(“Running with rank %d and size%d
“, rank, size);  printf(“The seed is : %d
“, BASE_SEED);    // Create and populate the array  int *my_array = (int *)malloc(N * sizeof(int));  srand(BASE_SEED + rank);    for(int c = 0; c < N; c++) {    my_arrayc = rand();  }  printf(" ");  printf(" "); // Start the timer as the sorting starts   start = MPI_Wtime();  int size = N/size;   // Divide the array in subarrays, send each subarray to a process.  int *sub_array = (int *)malloc(size * sizeof(int));  MPI_Scatter(my_array, size, MPI_INT, sub_array, size, MPI_INT, 0, MPI_COMM_WORLD);   // Perform the mergesort  int *tmp_array = (int *)malloc(size * sizeof(int));  mergeSort(sub_array, tmp_array, 0, (size - 1));   // Gather the sorted sub arrays into one array on the root process.  int *sorted_array = NULL;  if(rank == 0) {    sorted_array = (int *)malloc(N * sizeof(int));  }   MPI_Gather(sub_array, size, MPI_INT, sorted_array, size, MPI_INT, 0, MPI_COMM_WORLD);   // On the root finalize it by merging the subarrays.  if(rank == 0) {     int *other_array = (int *)malloc(n * sizeof(int));    mergeSort(sorted_array, other_array, 0, (N - 1));        end = MPI_Wtime();    printf("Time required was %lf seconds ", end-start);     // Display 10 partiotions of the sorted array to check if it is sorted.    printf("print 10 integers in partitioned array: ");    for(c = 0; c < 10; c++) {       printf("%d, ", sorted_array(n/10)*c);    }     printf(" ");    printf(" ");     // free arrays on root    free(sorted_array);    free(other_array);  }   // free arrays  free(my_array);  free(sub_array);  free(tmp_array);   MPI_Barrier(MPI_COMM_WORLD);  MPI_Finalize(); }/merge functionvoid merge(int *a, int *b, int l, int m, int r) {   int h, i, j, k;  h = l;  i = l;  j = m + 1;   while((h <= m) && (j <= r)) {    if(ah <= aj) {      bi = ah;      h++;    }     else {      bi = aj;      j++;    }    i++;   }   if(m < h) {    for(k = j; k <= r; k++) {      bi = ak;      i++;    }  }  else {    for(k = h; k <= m; k++) {      bi = ak;      i++;    }  }   for(k = l; k <= r; k++) {    ak = bk;  } }// mergesortvoid mergeSort(int *a, int *b, int l, int r) {  int mid;  if(l < r) {    mid = (l + r)/2;     mergeSort(a, b, l, mid);    mergeSort(a, b, (mid + 1), r);    merge(a, b, l, mid, r);  }}