-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.hpp
122 lines (89 loc) · 2.24 KB
/
common.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include <fstream>
#include <cstdint>
#include <sys/time.h>
#include <mutex>
#include <string>
#include <omp.h>
#include <algorithm>
#ifdef USE_TBB
#include <tbb/parallel_sort.h>
#endif
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
#define INLINE inline __attribute__((always_inline))
namespace hygraph {
typedef uint32_t vid_t;
typedef uint32_t eid_t;
enum EdgeDir {
EDGE_NONE = 0,
EDGE_OUT = 1,
EDGE_IN = 2,
EDGE_BOTH = 3
};
enum ActivityType {
ACTIVITY_ALWAYS,
ACTIVITY_SELECTED
};
typedef uint32_t bitvec_t;
#define BITVEC_GET(v, i) \
(((v))[(i) / 32] & (((uint32_t)1) << ((i) % 32)))
#define BITVEC_SET(v, i) \
(((v))[(i) / 32] |= (((uint32_t)1) << ((i) % 32)))
#define BITVEC_UNSET(v, i) \
(((v))[(i) / 32] &= ~(((uint32_t)1) << ((i) % 32)))
#define BITVEC_TOGGLE(v, i, f) \
((f) ? (BITVEC_SET(v, i)) : (BITVEC_UNSET(v, i)))
#define BITVEC_SIZE(s) \
(((s) / 32) + ((s) % 32 != 0 ? 1 : 0))
struct empty_t {
//
};
template <typename T>
struct is_empty_type {
static const bool value = false;
};
template <>
struct is_empty_type<empty_t> {
static const bool value = true;
};
template <typename T>
__host__ __device__ size_t ceil_div(T a, T b) {
return (a / b) + (a % b != 0);
}
static double timer() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec + tv.tv_usec / 1000000.0);
}
static std::mutex log_mutex;
static double log_start_time = 0;
template <typename ...A>
static void log(const char *fmt, A... args) {
log_mutex.lock();
if (log_start_time == 0) {
log_start_time = timer();
}
printf("[% 10.5f] ", timer() - log_start_time);
printf(fmt, args...);
printf("\n");
fflush(stderr);
fflush(stdout);
log_mutex.unlock();
}
static void log(const char *str) {
log("%s", str);
}
size_t get_file_size(const std::string &filename) {
std::ifstream f(filename.c_str(), std::ifstream::ate | std::ifstream::binary);
return f.tellg();
}
template <typename RandomIt, typename Compare>
INLINE void par_sort(RandomIt first, RandomIt last, Compare comp) {
#ifdef USE_TBB
tbb::parallel_sort(first, last, comp);
#else
sort(first, last, comp);
#endif
}
};