-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor.c
145 lines (106 loc) · 3.68 KB
/
executor.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
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
#include <stdio.h>
#include "operators/Kernel/operator.h"
// Allocates memory for the data used by the devito operator
void create_dataobj(struct dataobj* object, const char* filename)
{
FILE* file = fopen(filename, "r");
int size;
fscanf(file, "%d ", &size);
object->data = malloc(size * sizeof(float));
int shape_size;
fscanf(file, "%d", &shape_size);
object->size = malloc(shape_size * sizeof(int));
for (unsigned int i = 0; i < shape_size; ++i) {
fscanf(file, " %d", &object->size[i]);
}
fflush(file);
unsigned long pos = ftell(file) + 1;
fclose(file);
FILE* bfile = fopen(filename, "rb");
fseek(file, pos, SEEK_SET);
fread(object->data, size, sizeof(float), file);
fclose(bfile);
}
// Frees memory for the data used by the devito operator
void destroy_dataobj(struct dataobj* object)
{
free(object->data);
free(object->size);
}
int main(int argc, char* argv[])
{
// Initializes each variable
FILE* plot_file;
const float dt = 1.68;
const float o_x = -100.0;
const float o_y = -100.0;
const int x_M = 120;
const int x_m = 0;
const int y_M = 120;
const int y_m = 0;
const int p_rec_M = 100;
const int p_rec_m = 0;
const int p_src_M = 0;
const int p_src_m = 0;
const int time_M = 1191;
const int time_m = 1;
struct profiler * timers = malloc(sizeof(struct profiler));
struct dataobj * damp = malloc(sizeof(struct dataobj));
create_dataobj(damp, "dataobjs/damp.dataobj");
struct dataobj * rec = malloc(sizeof(struct dataobj));
create_dataobj(rec, "dataobjs/rec.dataobj");
struct dataobj * rec_coords = malloc(sizeof(struct dataobj));
create_dataobj(rec_coords, "dataobjs/rec_coords.dataobj");
struct dataobj * src = malloc(sizeof(struct dataobj));
create_dataobj(src, "dataobjs/src.dataobj");
struct dataobj * src_coords = malloc(sizeof(struct dataobj));
create_dataobj(src_coords, "dataobjs/src_coords.dataobj");
struct dataobj * u = malloc(sizeof(struct dataobj));
create_dataobj(u, "dataobjs/u.dataobj");
struct dataobj * vp = malloc(sizeof(struct dataobj));
create_dataobj(vp, "dataobjs/vp.dataobj");
// Saves damp data in human readable format
if (plot_file = fopen("saves/damp.save", "w")) {;
fprintf(plot_file, "123 123\n");
for (unsigned int i0 = 0; i0 < 123; ++i0) {
for (unsigned int i1 = 0; i1 < 123; ++i1) {
float (*restrict damp_temp__)[damp->size[1]] __attribute__ ((aligned (64))) = (float (*)[damp->size[1]]) damp->data;
fprintf(plot_file, "%f", damp_temp__[i0][i1]);
}
}
fclose(plot_file);
plot_file = NULL;
}
// Executes the operator
Kernel(damp, dt, o_x, o_y, rec, rec_coords, src, src_coords, u, vp, x_M, x_m, y_M, y_m, p_rec_M, p_rec_m, p_src_M, p_src_m, time_M, time_m, timers);
// Saves variables for future plotting in binary format
if (plot_file = fopen("saves/u.save", "w")) {;
fprintf(plot_file, "1193 125 125\n");
fwrite(u->data, sizeof(float), 18640625, plot_file);
fclose(plot_file);
plot_file = NULL;
}
if (plot_file = fopen("saves/rec.save", "w")) {;
fprintf(plot_file, "1192 101\n");
fwrite(rec->data, sizeof(float), 120392, plot_file);
fclose(plot_file);
plot_file = NULL;
}
// Frees memory for allocated variables
free(timers);
destroy_dataobj(damp);
free(damp);
destroy_dataobj(rec);
free(rec);
destroy_dataobj(rec_coords);
free(rec_coords);
destroy_dataobj(src);
free(src);
destroy_dataobj(src_coords);
free(src_coords);
destroy_dataobj(u);
free(u);
destroy_dataobj(vp);
free(vp);
return 0;
}