forked from starkantoden/Hybrid_Sort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
87 lines (80 loc) · 2.03 KB
/
util.h
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
78
79
80
81
82
83
84
85
86
87
#ifndef _Windows
#include <stdio.h>
#endif
#include <algorithm>
#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_real.hpp>
/*#ifndef _Windows
typedef size_t rsize_t;
#endif*/
void GenerateData(int seed, float *data, size_t N)
{
boost::minstd_rand generator(seed);
boost::uniform_real<float> floatDist(1.0, 6.0);
for (size_t i = 0; i < N; i++)
{
data[i] = floatDist(generator);
}
}
template<typename T>bool resultTest(T *data, size_t N)
{
for (size_t i = 0; i < N - 1; i++)
{
//if (data[i] > data[i + 1] || data[i] == 0)
if (data[i] > data[i + 1])
{
std::cout << "unsorted at fucking " << i << "! " << std::endl;
std::cout << "fail value: " << data[i] << " " << data[i + 1]
<< std::endl;
return false;
}
}
std::cout << "successfully sorted!" << std::endl;
return true;
}
template<typename T>void resultCheck(T* dataA, T* dataB, size_t N)
{
std::sort(dataA, dataA + N);
for (size_t i = 0; i < N; ++i)
{
if(dataA[i] != dataB[i])
std::cout << "inconsistent at " << i << " " << dataA[i] << " "
<< dataB[i] << std::endl;
}
}
inline size_t cacheSizeInByte()
{
size_t size = 0;
#ifndef _Windows
FILE *fptr = 0;
fptr = fopen("/sys/devices/system/cpu/cpu0/cache/index0/size", "r");
if(fptr)
{
char size_type;
if (fscanf(fptr, "%lu%c", &size, &size_type) != 2)
size = 0;
if(size_type == 'K') size *= 1024;
fclose(fptr);
}
#endif
//std::cout << "cache size selected: " << size << std::endl;
return size;
}
inline size_t cacheSizeInByte3()
{
size_t size = 0;
#ifndef _Windows
FILE *fptr = 0;
fptr = fopen("/sys/devices/system/cpu/cpu0/cache/index3/size", "r");
if(fptr)
{
char size_type;
if (fscanf(fptr, "%lu%c", &size, &size_type) != 2)
size = 0;
if(size_type == 'K') size *= 1024;
fclose(fptr);
}
#endif
//std::cout << "cache size selected: " << size << std::endl;
return size;
}