Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
18BCE2182 ASSESS_3 Q3
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//gcc 7.4.0 #include <stdio.h> #include <stdlib.h> #include <omp.h> void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) { L[i] = arr[l + i]; } for (j = 0; j < n2; j++) { R[j] = arr[m + 1 + j]; } i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void mergeSort(int arr[], int l, int r) { if (l < r) { int m = l + (r - l) / 2; mergeSort(arr, l, m); mergeSort(arr, m + 1, r); merge(arr, l, m, r); } } void quicksort(int number[], int first, int last) { int i, j, pivot, temp; if (first < last) { pivot = first; i = first; j = last; while (i < j) { while (number[i] <= number[pivot] && i < last) i++; while (number[j] > number[pivot]) j--; if (i < j) { temp = number[i]; number[i] = number[j]; number[j] = temp; } } temp = number[pivot]; number[pivot] = number[j]; number[j] = temp; quicksort(number, first, j - 1); quicksort(number, j + 1, last); } } void sequentially(int arr[], int n) { quicksort(arr, 0, n); mergeSort(arr, 0, n); } int main() { int n=10; int arr[n]; for (int i = 0; i < n; i++) { arr[i] = rand() % 1000; } double start = omp_get_wtime(); sequentially(arr, n); double end = omp_get_wtime(); printf("time took sequentially %lf \n", end - start); start = omp_get_wtime(); #pragma omp parallel { #pragma omp sections { #pragma omp section { mergeSort(arr, 0, n); } #pragma omp section { quicksort(arr, 0, n); } } } end = omp_get_wtime(); printf("time took parallely %lf \n", end - start); }
gcc
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.22 sec, absolute running time: 0.16 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 0,43 sec
edit mode
|
history
|
discussion
time took sequentially 0.000002 time took parallely 0.001869