-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.c
57 lines (53 loc) · 1.72 KB
/
utils.c
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
/* Copyright (C) 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 __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include "splittable_mrg.h"
#include "graph_generator.h"
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef __MTA__
#include <sys/mta_task.h>
#endif
#ifdef GRAPH_GENERATOR_MPI
#include <mpi.h>
#endif
#ifdef GRAPH_GENERATOR_OMP
#include <omp.h>
#endif
#include "utils.h"
void* xmalloc(size_t n) {
void* p = malloc(n);
if (!p) {
fprintf(stderr, "Out of memory trying to allocate %zu byte(s)\n", n);
abort();
}
return p;
}
void* xcalloc(size_t n, size_t k) {
void* p = calloc(n, k);
if (!p) {
fprintf(stderr, "Out of memory trying to allocate %zu byte(s)\n", n);
abort();
}
return p;
}
/* Spread the two 64-bit numbers into five nonzero values in the correct
* range. */
void make_mrg_seed(uint64_t userseed1, uint64_t userseed2, uint_fast32_t* seed) {
seed[0] = (userseed1 & 0x3FFFFFFF) + 1;
seed[1] = ((userseed1 >> 30) & 0x3FFFFFFF) + 1;
seed[2] = (userseed2 & 0x3FFFFFFF) + 1;
seed[3] = ((userseed2 >> 30) & 0x3FFFFFFF) + 1;
seed[4] = ((userseed2 >> 60) << 4) + (userseed1 >> 60) + 1;
}