-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.c
58 lines (47 loc) · 1.16 KB
/
generator.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
58
#include "opencl_lab2.h"
int generate(int n) {
float* src = malloc(n * sizeof(float));
if (src == NULL) {
printf("[generator] Not enough memory");
return -1;
}
for (int i = 0; i < n; i++) {
src[i] = (float) (rand() % 2) / 2;
}
FILE* F = fopen("generated.in", "wb");
if (F == NULL) {
printf("[generator] Can't open input file");
free(src);
return -1;
}
fprintf(F, "%i\n", n);
for (int i = 0; i < n; i++) {
fprintf(F, "%f ", src[i]);
}
fclose(F);
float* dst = malloc(n * sizeof(float));
if (dst == NULL) {
printf("[generator] Not enough memory");
return -1;
}
printf("Generating sample size %i...\n", n);
float sum = 0;
for (int i = 0; i < n; i++) {
sum += src[i];
dst[i] = sum;
}
free(src);
F = fopen("generated_res.out", "wb");
if (F == NULL) {
printf("[generator] Can't open output file");
free(dst);
return -1;
}
fprintf(F, "%i\n", n);
for (int i = 0; i < n; i++) {
fprintf(F, "%f ", dst[i]);
}
fclose(F);
printf("Generated\n");
return 0;
}