We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
Sardar Vallabhbhai National Institute of Technology
B. Tech. Ill (CSE) Semester — V
Parallel Processing & Architecture (Core Elective-1)
CS323
Lab-10
(1) Write an OpenMp program to implement parallel merge sort without using and with
using “pragma omp for” directive. Provide a running time comparison of mentioned
two parallel versions of merge sort algorithm with an algorithm that sequentially does
the same thing for a larger array.
Code :-
Hinclude
Hinclude
#include
#include
void merge(int art{], int left, int mid, int right) {
inti, j,k;
int nl = mid - left +1;
int n2 = right - mid;int *L = (int *)malloc(n1 * sizeof{int))
int *R = (int *)malloc(n2 * sizeoftint));
for (i=0; i 1000)
parallelMergeSortNoFor(ar, lef, mid);
#pragma omp task shared(arr) if{right - left > 1000)
parallelMergeSortNoFor(arr, mid + 1, right);#pragma omp taskwait
merge(arr, left, mid, right);
// Parallel merge sort with #pragma omp for
void parallelMergeSortWithFor(int arr, int lef, int right) {
if (left
include
#include include
void generate_histogram_locks(int *histogram, int N, int M) {
‘omp_lock_t lock:
‘omp_init_lock( lock);
pragma omp parallel
t
pragma omp for
for (int i= 0; i