-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataGenerator.c
More file actions
162 lines (121 loc) · 3.21 KB
/
DataGenerator.c
File metadata and controls
162 lines (121 loc) · 3.21 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include "DataGenerator.h"
#define RANDOM 0
#define INCREASING 1
#define IDENTICAL 2
#define EXCLUSIVE 3
int data_flag;
relation* create_relation_R(){
int i;
int maxValue = (int) MAX_VALUE;
relation* relR = malloc(sizeof(relation));
srand((unsigned int) time(0));
relR->num_tuples = (uint32_t) RELR_SIZE;
relR->tuples = malloc(relR->num_tuples * sizeof(tuple));
for(i=0; i<relR->num_tuples; i++){
relR->tuples[i].key = (int32_t ) i;
if (data_flag == RANDOM)
{
relR->tuples[i].payload = rand() % MAX_VALUE;
}
else if (data_flag == INCREASING)
{
relR->tuples[i].payload = i;
}
else if (data_flag == IDENTICAL)
{
relR->tuples[i].payload = 1;
}
else if (data_flag == EXCLUSIVE)
{
relR->tuples[i].payload = 1;
}
else
{
relR->tuples[i].payload = 0;
}
}
return relR;
}
relation* create_relation_S(){
int i;
int maxValue = (int) MAX_VALUE;
relation* relS = malloc(sizeof(relation));
sleep(1); // Needs this otherwise parallel execution of threads creates same relations R and S
srand((unsigned int) time(0));
relS->num_tuples = (uint32_t) RELS_SIZE;
relS->tuples = malloc(relS->num_tuples * sizeof(tuple));
for(i=0; i<relS->num_tuples; i++){
relS->tuples[i].key = (int32_t ) i;
if (data_flag == RANDOM)
{
relS->tuples[i].payload = rand() % MAX_VALUE;
}
else if (data_flag == INCREASING)
{
relS->tuples[i].payload = i;
}
else if (data_flag == IDENTICAL)
{
relS->tuples[i].payload = 1;
}
else if (data_flag == EXCLUSIVE)
{
relS->tuples[i].payload = 2;
}
else
{
relS->tuples[i].payload = 0;
}
}
return relS;
}
void print_to_file_R(){
FILE* file = fopen(relR_name, "w");
relation* relR = create_relation_R();
for(int i=0; i<relR->num_tuples; i++){
fprintf(file, "%d\n", relR->tuples[i].payload);
}
fclose(file);
}
void print_to_file_S(){
FILE* file = fopen(relS_name, "w");
relation* relS = create_relation_S();
for(int i=0; i<relS->num_tuples; i++){
fprintf(file, "%d\n", relS->tuples[i].payload);
}
fclose(file);
}
int main(int argc, char **argv){
if (argc==1)
{
fprintf(stderr, "Random payloads\n");
data_flag = RANDOM;
}
else if ((strncmp(argv[1], "1", sizeof(char)))==0)
{
fprintf(stderr, "Increasing payloads\n");
data_flag = INCREASING;
}
else if ((strncmp(argv[1], "2", sizeof(char)))==0)
{
fprintf(stderr, "Identical payloads\n");
data_flag = IDENTICAL;
}
else if ((strncmp(argv[1], "3", sizeof(char)))==0)
{
fprintf(stderr, "Exclusive per relation payloads\n");
data_flag = EXCLUSIVE;
}
else
{
fprintf(stderr, "Random payloads\n");
data_flag = RANDOM;
}
print_to_file_R();
print_to_file_S();
}