-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.h
58 lines (48 loc) · 1.41 KB
/
helpers.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
#include <stdlib.h>
#include <time.h>
#include "defs.h"
void printMatrixH(uint32_t *a, uint32_t size, char *text) {
DEBUG_PRINT(("%s: ", text));
for (int i = 0; i < size; i++)
DEBUG_PRINT(("%d ", a[i]));
DEBUG_PRINT(("\n"));
}
void printMatrixV(uint32_t *a, uint32_t size, char *text) {
DEBUG_PRINT(("------- %s: \n", text));
for (int i = 0; i < size; i++)
DEBUG_PRINT(("%d: %d\n", i, a[i]));
DEBUG_PRINT(("\n"));
}
void printMatrix2Dims(void *arr, int n, int m) {
int *a = (int *)arr;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
DEBUG_PRINT(("%d ", a[i * m + j]));
DEBUG_PRINT(("\n"));
}
}
void initRandomGraph(void *arr, int n, int m) {
int *a = (int *)arr;
srandom(time(NULL));
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < m; j++) {
// Check if an IF is faster (if random() & 1 => A[i][j] = 1 etc)
int r = random() & 1;
a[i * m + j] = r;
a[j * m + i] = r;
}
}
}
// bool A[RAND_N][RAND_N];
// void randomGraph(uint32_t *c3) {
// initRandomGraph(A, RAND_N, RAND_N);
// timerStart();
// triangleCountV2(A, RAND_N, RAND_N, c3);
// timerEnd();
// timerPrint("v2");
// timerStart();
// triangleCountV1(A, RAND_N, RAND_N, c3);
// timerEnd();
// timerPrint("v1");
// printMatrix2Dims(A, RAND_N, RAND_N);
// }