35 #ifndef _REF_GEN_2_1_H_ 36 #define _REF_GEN_2_1_H_ 41 #ifdef _GCC_STDINT_H // for cray 42 #undef _GCC_STDINT_H // original stdint does #include_next<"/opt/gcc/4.5.2/snos/lib/gcc/x86_64-suse-linux/4.5.2/include/stdint-gcc.h"> 45 #ifndef __STDC_CONSTANT_MACROS 46 #define __STDC_CONSTANT_MACROS 48 #ifndef __STDC_LIMIT_MACROS 49 #define __STDC_LIMIT_MACROS 73 #define INITIATOR_A_NUMERATOR 5700 74 #define INITIATOR_BC_NUMERATOR 1900 75 #define INITIATOR_DENOMINATOR 10000 84 #define SPK_NOISE_LEVEL 0 95 seed[0] = (userseed & 0x3FFFFFFF) + 1;
96 seed[1] = ((userseed >> 30) & 0x3FFFFFFF) + 1;
97 seed[2] = (userseed & 0x3FFFFFFF) + 1;
98 seed[3] = ((userseed >> 30) & 0x3FFFFFFF) + 1;
99 seed[4] = ((userseed >> 60) << 4) + (userseed >> 60) + 1;
114 #if SPK_NOISE_LEVEL == 0 115 int spk_noise_factor = 0;
121 if ((
signed)val < adjusted_bc_numerator)
return 1;
122 val -= adjusted_bc_numerator;
123 if ((
signed)val < adjusted_bc_numerator)
return 2;
124 val -= adjusted_bc_numerator;
125 #if SPK_NOISE_LEVEL == 0 138 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) 139 #define USE_GCC_BYTESWAP 142 #ifdef FAST_64BIT_ARITHMETIC 145 #ifdef USE_GCC_BYTESWAP 146 x = __builtin_bswap64(x);
148 x = (x >> 32) | (x << 32);
149 x = ((x >> 16) & UINT64_C(0x0000FFFF0000FFFF)) | ((x & UINT64_C(0x0000FFFF0000FFFF)) << 16);
150 x = ((x >> 8) & UINT64_C(0x00FF00FF00FF00FF)) | ((x & UINT64_C(0x00FF00FF00FF00FF)) << 8);
152 x = ((x >> 4) & UINT64_C(0x0F0F0F0F0F0F0F0F)) | ((x & UINT64_C(0x0F0F0F0F0F0F0F0F)) << 4);
153 x = ((x >> 2) & UINT64_C(0x3333333333333333)) | ((x & UINT64_C(0x3333333333333333)) << 2);
154 x = ((x >> 1) & UINT64_C(0x5555555555555555)) | ((x & UINT64_C(0x5555555555555555)) << 1);
160 uint32_t h = (uint32_t)(x >> 32);
161 uint32_t l = (uint32_t)(x & UINT32_MAX);
162 #ifdef USE_GCC_BYTESWAP 163 h = __builtin_bswap32(h);
164 l = __builtin_bswap32(l);
166 h = (h >> 16) | (h << 16);
167 l = (l >> 16) | (l << 16);
168 h = ((h >> 8) & UINT32_C(0x00FF00FF)) | ((h & UINT32_C(0x00FF00FF)) << 8);
169 l = ((l >> 8) & UINT32_C(0x00FF00FF)) | ((l & UINT32_C(0x00FF00FF)) << 8);
171 h = ((h >> 4) & UINT32_C(0x0F0F0F0F)) | ((h & UINT32_C(0x0F0F0F0F)) << 4);
172 l = ((l >> 4) & UINT32_C(0x0F0F0F0F)) | ((l & UINT32_C(0x0F0F0F0F)) << 4);
173 h = ((h >> 2) & UINT32_C(0x33333333)) | ((h & UINT32_C(0x33333333)) << 2);
174 l = ((l >> 2) & UINT32_C(0x33333333)) | ((l & UINT32_C(0x33333333)) << 2);
175 h = ((h >> 1) & UINT32_C(0x55555555)) | ((h & UINT32_C(0x55555555)) << 1);
176 l = ((l >> 1) & UINT32_C(0x55555555)) | ((l & UINT32_C(0x55555555)) << 1);
177 return ((uint64_t)l << 32) | h;
187 uint64_t v = (uint64_t)v0;
189 v *= (val0 | UINT64_C(0x4519840211493211));
191 assert ((v >> lgN) == 0);
192 v *= (val1 | UINT64_C(0x3050852102C843A5));
194 assert ((v >> lgN) == 0);
201 int64_t base_src = 0, base_tgt = 0;
205 int src_offset = square / 2;
206 int tgt_offset = square % 2;
207 assert (base_src <= base_tgt);
208 if (base_src == base_tgt)
211 if (src_offset > tgt_offset) {
212 int temp = src_offset;
213 src_offset = tgt_offset;
219 base_src += nverts * src_offset;
220 base_tgt += nverts * tgt_offset;
223 scramble(base_src, lgN, val0, val1),
224 scramble(base_tgt, lgN, val0, val1));
234 val0 *= UINT64_C(0xFFFFFFFF);
237 val1 *= UINT64_C(0xFFFFFFFF);
254 #pragma omp parallel for 256 for (
int64_t ei = start_edge; ei < end_edge; ++ei)
260 make_one_edge(nverts, 0, logN, &new_state, edges + (ei - start_edge), val0, val1);
267 *start_idx = rankc * (M / sizec) + (rankc < (M % sizec) ? rankc : (M % sizec));
268 *end_idx = (rankc + 1) * (M / sizec) + (rankc + 1 < (M % sizec) ? rankc + 1 : (M % sizec));
275 uint64_t userseed1 = 0;
281 uint_fast32_t seed[5];
284 MPI_Comm_rank(world, &rank);
285 MPI_Comm_size(world, &size);
289 int64_t nedges = end_idx - start_idx;
293 double start = MPI_Wtime();
295 double gen_time = MPI_Wtime() - start;
297 *result_ptr = local_edges;
298 *nedges_ptr = nedges;
302 fprintf(stdout,
"graph_generation: %f s\n", gen_time);
312 seed = strtol (getenv (
"SEED"), NULL, 10);
313 if (errno) seed = -1;
316 if (seed < 0) seed = 0xDECAFBAD;
static int generate_4way_bernoulli(mrg_state *st, int level, int nlevels)
static uint64_t bitreverse(uint64_t x)
void mrg_skip(mrg_state *state, uint_least64_t exponent_high, uint_least64_t exponent_middle, uint_least64_t exponent_low)
#define INITIATOR_A_NUMERATOR
static void make_graph(int log_numverts, int64_t M, int64_t *nedges_ptr, packed_edge **result_ptr, MPI_Comm &world)
void mrg_seed(mrg_state *st, const uint_fast32_t seed[5])
static int64_t scramble(int64_t v0, int lgN, uint64_t val0, uint64_t val1)
uint_fast32_t mrg_get_uint_orig(mrg_state *state)
#define INITIATOR_DENOMINATOR
static void make_one_edge(int64_t nverts, int level, int lgN, mrg_state *st, packed_edge *result, uint64_t val0, uint64_t val1)
void make_mrg_seed(uint64_t userseed1, uint64_t userseed2, uint_fast32_t *seed)
static long init_random()
static void make_mrg_seed_short(uint64_t userseed, uint_fast32_t *seed)
static void generate_kronecker_range(const uint_fast32_t seed[5], int logN, int64_t start_edge, int64_t end_edge, packed_edge *edges)
static mrg_state MakeScrambleValues(uint64_t &val0, uint64_t &val1, const uint_fast32_t seed[])
static void compute_edge_range(int rank, int size, int64_t M, int64_t *start_idx, int64_t *end_idx)
#define INITIATOR_BC_NUMERATOR