Professional Documents
Culture Documents
ShamikDISHA GIDWANI
Puranik
BATCH:
Panel: F1
B
ROLL NO.: 06
Batch: B1
HPC LAB 5
Roll No: 09
HPC Lab – 05
Objective:
1. Write sequential Quick Sort or Breadth First Search or
Depth first Search
2. Calculate complexity of the program
3. Write parallel Quick Sort or Breadth First Search or
Depth first Search
4. Calculate complexity of the program
5. Measure and compare time taken by the parallel
Quick Sort or Breadth First Search or Depth first Search
with respect to the serial
Theory:
FAQs:
therefore,
T(n) = 2*T(n/2) + constant*n
further we will devide arrai in to array of equalsize
so
T(n) = 2*(2*T(n/4) + constant*n/2) + constant*n ==
4*T(n/4) + 2*constant*n
therefore,
T(n) = n * T(1) + n*logn = O(n*log2(n))
#include<stdio.h>
#include<stdlib.h>
#include<omp.h>
long long k = 0;
int partition(long long *arr,long long lb,long long ub)
{
long long x = arr[ub];
long long i = lb-1;
long long j;
for(j=lb;j<ub;j++)
{
if(arr[j]<=x)
{
i=i+1;
long long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
long long temp = arr[i+1];
arr[i+1] = arr[ub];
arr[ub] = temp;
return i+1;
}
double quicksort_serial(long long *arr,long long lb,long
long ub)
{
long long j;
double start = omp_get_wtime();
if(lb<ub)
{
j = partition(arr,lb,ub);
quicksort_serial(arr,lb,j-1);
quicksort_serial(arr,j+1,ub);
}
double end = omp_get_wtime();
return end-start;
}
double quicksort_parallel(long long *arr,long long lb,long
long ub)
{
long long p;
double start = omp_get_wtime();
if(lb<ub)
{
p = partition(arr,lb,ub);
Output: