-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
78 lines (64 loc) · 2.34 KB
/
main.c
File metadata and controls
78 lines (64 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <omp.h>
#include <inttypes.h>
#include <stdlib.h>
#include "mt19937-64.h"
#include "./include/comparisons_floats.h"
#include "include/merge_sort.h"
#include "tests/array_generators.h"
#include "include/issorted.h"
#include "include/bubble_sort.h"
#include "include/selection_sort.h"
#include "include/insertion_sort.h"
#include "include/gnome_sort.h"
#include "include/quick_sort.h"
#include "include/heap_sort.h"
#include "tests/tests_partition.h"
#define ARRAY_SIZE(x) (sizeof(x)/(sizeof((x)[0])))
typedef void (*sorting_function_t)(void*, size_t, size_t, __compar_fn_t);
int main(void) {
// Declare array of floats
double start, delta;
size_t const len_array_double = 4096<<5;
double* array_double = calloc(len_array_double, sizeof(double));
__compar_fn_t cmp = cmp_less_fp64;
sorting_function_t sorting_function = gnome_sort;
// fill it with shorts from Mersenne Twister
start = omp_get_wtime();
uint64_t seed = array_fill_fp64(array_double, len_array_double, mt_seed, rand_double);
delta = omp_get_wtime() - start;
printf("Mersenne Twister seed: %" PRId64 "\n", seed);
printf("Generated %zu floats in %.4f sec.\n\n", len_array_double, delta);
//<editor-fold desc="Display contents (array_double pre-sort)">
if (len_array_double <= 128) {
for (size_t i = 0; i < len_array_double; ++i) {
printf("%.2f, ", array_double[i]);
if ((i + 1) % 16 == 0) printf("\n");
}
printf("\n\n");
}
//</editor-fold>
// Sort the array and store the time duration into 'delta'
start = omp_get_wtime();
sorting_function(array_double, len_array_double, sizeof(double), cmp);
delta = omp_get_wtime() - start;
//<editor-fold desc="Check if the array is sorted">
int issort = issorted(array_double, len_array_double, sizeof(double), cmp);
if (issort) {
printf("array was sorted in %.4f sec.\n", delta);
} else {
printf("array failed to sort\n");
}
//</editor-fold>
//<editor-fold desc="Display contents (array_double)">
if (len_array_double <= 128) {
for (size_t i = 0; i < len_array_double; ++i) {
printf("%.2f, ", array_double[i]);
if ((i+1)% 16 == 0) printf("\n");
}
printf("\n");
}
//</editor-fold>
free(array_double);
return 0;
}