what is the amount of read and write contention and synchronization overheads for the following OpenMP shared memory program? int main(int argc, char** argv) { double start_time, run_time; int* arr =...


what is the amount of read and write contention and synchronization overheads for the following OpenMP shared memory program?



int main(int argc, char** argv) {
   double start_time, run_time;
   int* arr = NULL;


   if (!(argc >= 3)) {
       printf("Number of array elements must be provided as first argument and number of threads as second argument to program\n");
       exit(-1);
   }


   int n = atoi(argv[1]);
   int p = atoi(argv[2]);
   arr = (int*)malloc(n * sizeof(int));


   for (int i = 0; i < n;="" i++)="">
       arr[i] = (rand() % 99999) + 1;
   }


   int pi = partition(arr, 0, n-1);


   start_time = omp_get_wtime();


#pragma omp parallel sections
{
       #pragma omp section
       {
           quickSort(arr,0, pi - 1);
       }
       #pragma omp section
       {
           quickSort(arr, pi + 1, n-1);
       }


}   run_time = omp_get_wtime() - start_time;
   omp_set_num_threads(p);


   start_time = omp_get_wtime();
   #pragma omp parallel
       {
           #pragma omp single nowait
           quickSort(arr, 0, n - 1);
       }


   run_time += omp_get_wtime() - start_time;
   printf("\n Execution time was %lf seconds\n ", run_time);
   printf("Sorted array: \n");
   printArray(arr, n);
   printf("\n");
   return 0;
}



Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here