-
Notifications
You must be signed in to change notification settings - Fork 6
/
graph_generator.h
executable file
·86 lines (68 loc) · 2.48 KB
/
graph_generator.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
/* Copyright (C) 2009-2010 The Trustees of Indiana University. */
/* */
/* Use, modification and distribution is subject to the Boost Software */
/* License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at */
/* http://www.boost.org/LICENSE_1_0.txt) */
/* */
/* Authors: Jeremiah Willcock */
/* Andrew Lumsdaine */
#ifndef GRAPH_GENERATOR_H
#define GRAPH_GENERATOR_H
#include "user_settings.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef GENERATOR_USE_PACKED_EDGE_TYPE
typedef struct packed_edge {
uint32_t v0_low;
uint32_t v1_low;
uint32_t high; /* v1 in high half, v0 in low half */
} packed_edge;
static inline int64_t get_v0_from_edge(const packed_edge* p) {
return (p->v0_low | ((int64_t)((int16_t)(p->high & 0xFFFF)) << 32));
}
static inline int64_t get_v1_from_edge(const packed_edge* p) {
return (p->v1_low | ((int64_t)((int16_t)(p->high >> 16)) << 32));
}
static inline void write_edge(packed_edge* p, int64_t v0, int64_t v1) {
p->v0_low = (uint32_t)v0;
p->v1_low = (uint32_t)v1;
p->high = (uint32_t)(((v0 >> 32) & 0xFFFF) | (((v1 >> 32) & 0xFFFF) << 16));
}
#else
typedef struct packed_edge {
int64_t v0;
int64_t v1;
} packed_edge;
static inline int64_t get_v0_from_edge(const packed_edge* p) {
return p->v0;
}
static inline int64_t get_v1_from_edge(const packed_edge* p) {
return p->v1;
}
static inline void write_edge(packed_edge* p, int64_t v0, int64_t v1) {
p->v0 = v0;
p->v1 = v1;
}
#endif
/* Generate a range of edges (from start_edge to end_edge of the total graph),
* writing into elements [0, end_edge - start_edge) of the edges array. This
* code is parallel on OpenMP and XMT; it must be used with
* separately-implemented SPMD parallelism for MPI. */
void generate_kronecker_range(
const uint_fast32_t seed[5] /* All values in [0, 2^31 - 1) */,
int logN /* In base 2 */,
int64_t start_edge, int64_t end_edge /* Indices (in [0, M)) for the edges to generate */,
packed_edge* edges /* Size >= end_edge - start_edge */
);
#ifdef __cplusplus
}
#endif
#endif /* GRAPH_GENERATOR_H */