forked from milc-qcd/milc_qcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_mb2.c
219 lines (191 loc) · 5.27 KB
/
output_mb2.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*********************** output_mb2.c *************************/
/* MIMD version 7 */
/* routines for meson hopping expansion binary input/output. */
#include "w_heavy_includes.h"
#include <fcntl.h> /** raw UNIX calls **/
#include <errno.h>
/* write binary meson propagators */
/*
format:
version_number (int)
nx ny nz nt (int)
beta kappa_light (Real)
width^-2 (Real), wallflag(int)
wall_cutoff (int), wall_separation (int)
kappa_c (Real)
total_number_of_hopping_iters (int)
for spin{ for color{
for(N_iter)
spin color N_iter
prop
*/
/* this subroutine opens the file for writing */
int w_binary_m_i(char *filenam, int i1)
{
int fp;
int32type dims[4];
int32type i_out;
/* node 0 does all the writing */
if (this_node == 0)
{
printf(" meson output file is named %s\n", filenam);
fp = creat(filenam, 0664);
if (fp < 0)
{
printf("Can't open file %s, error %d\n", filenam, errno);
terminate(1);
}
i_out = VERSION_NUMBER;
if ((write(fp, &i_out, sizeof(int32type))) != sizeof(int32type))
{
printf("Error in writing meson prop header\n");
terminate(1);
}
dims[XUP] = nx;
dims[YUP] = ny;
dims[ZUP] = nz;
dims[TUP] = nt;
if ((write(fp, dims, 4 * sizeof(int32type))) != 4 * sizeof(int32type))
{
printf("Error in writing meson prop header\n");
terminate(1);
}
if ((write(fp, &beta, sizeof(Real))) != sizeof(Real))
{
printf("Error in writing meson header beta\n");
terminate(1);
}
if ((write(fp, &kappa, sizeof(Real))) != sizeof(Real))
{
printf("Error in writing meson header kappa\n");
terminate(1);
}
i_out = i1;
if ((write(fp, &i_out, sizeof(int32type))) != sizeof(int32type))
{
printf("Error in writing meson header i1\n");
terminate(1);
}
if ((write(fp, &width, sizeof(Real))) != sizeof(Real))
{
printf("Error in writing meson header width\n");
terminate(1);
}
i_out = wqs.type;
if ((write(fp, &i_out, sizeof(int32type))) != sizeof(int32type))
{
printf("Error in writing meson header wallflag\n");
terminate(1);
}
i_out = wqs.wall_cutoff;
if ((write(fp, &i_out, sizeof(int32type))) != sizeof(int32type))
{
printf("Error in writing meson header wall_cutoff\n");
terminate(1);
}
i_out = wall_separation;
if ((write(fp, &i_out, sizeof(int32type))) != sizeof(int32type))
{
printf("Error in writing meson header wall_separation\n");
terminate(1);
}
if ((write(fp, &kappa_c, sizeof(Real))) != sizeof(Real))
{
printf("Error in writing meson header kappa_c\n");
terminate(1);
}
i_out = nhop;
if ((write(fp, &i_out, sizeof(int32type))) != sizeof(int32type))
{
printf("Error in writing meson header nhop\n");
terminate(1);
}
}
else fp = -1; /* If not node zero */
return fp;
}
/* this subroutine opens the file for writing but does not write headers */
int a_binary_m_i(char *filenam, int i1)
{
int fd;
/* node 0 does all the writing */
if (this_node == 0)
{
printf(" meson output file is named %s\n", filenam);
fd = open(filenam, O_WRONLY, 0);
if (fd < 0)
{
printf("Can't open file %s, error %d\n", filenam, errno);
terminate(1);
}
}
else fd = -1; /* If not node 0 */
return fd;
}
/* this subroutine writes a meson propagator */
/*
* all nodes have the same summed meson propagator at this point so node 0
* does all the work
*/
void w_binary_m(int fp, int spin, int color, int iter, double *prop[])
{
int32type ints[3];
int channel, t, tp, nw1, nw2;
long head_size, offset, body_size, meson_prop_size, declare_spin_color_etc;
long ls1, ls2;
static Real *temp;
static int firsttime = 1;
g_sync();
head_size = 10 * sizeof(int32type) + 4 * sizeof(Real);
declare_spin_color_etc = 3 * sizeof(int32type);
meson_prop_size = nchannels * nt * sizeof(Real);
body_size = declare_spin_color_etc + meson_prop_size;
body_size = ((1 + iter) + (1 + nhop) * (color + 3 * spin)) * body_size;
offset = head_size + body_size;
if (this_node == 0)
{
ls1 = lseek(fp, offset, 0);
/* first the spin and color and iteration_number */
ints[0] = spin;
ints[1] = color;
ints[2] = iter;
if ((nw1 = write(fp, ints, 3 * sizeof(int32type))) != 3 * sizeof(int32type))
{
printf("Write error in save_binary\n");
terminate(1);
}
ls2 = lseek(fp, 0L, 1);
/* next the elements */
/* write Reals to save space */
if (firsttime)
{
temp = (Real *) malloc(nt * sizeof(Real));
firsttime = 0;
}
for (channel = 0; channel < nchannels; channel++)
{
/* undo even-slices-first order */
for (t = 0; t < nt; t++)
{
tp = (t % 2) * (nt / 2) + t / 2;
temp[t] = prop[channel][tp];
}
if ((nw2 = write(fp, temp, nt * sizeof(Real))) != nt * (int)sizeof(Real))
{
printf("Write error in w_binary_m\n");
terminate(1);
}
}
} /* node 0 */
g_sync();
} /* w_binary_m */
/* this subroutine closes the file */
void w_binary_m_f(int fp, char *filenam)
{
g_sync();
if (this_node == 0)
{
printf("Saved binary meson propagator in file %s\n", filenam);
close(fp);
}
}