-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.c
208 lines (170 loc) · 6.48 KB
/
setup.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
// -----------------------------------------------------------------
// SU(3) stochastic mode number calculation setup
#include "mode_includes.h"
#include <string.h>
#define IF_OK if (status == 0)
// Each node has a params structure for passing simulation parameters
#include "params.h"
params par_buf;
// -----------------------------------------------------------------
// -----------------------------------------------------------------
// On node zero, read lattice size, seed and send to others
int initial_set() {
int prompt, status;
if (mynode() == 0) {
// Print banner
printf("SU(3) with Kogut--Susskind fermions\n");
printf("Stochastic mode number measurement\n");
printf("Machine = %s, with %d nodes\n", machine_type(), numnodes());
printf("nHYP links, reading alpha_smear parameters from infile\n");
printf(" IR_STAB = %.4g\n", (Real)IR_STAB);
printf(" EPS_SQ = %.4g\n", (Real)EPS_SQ);
#ifdef NHYP_DEBUG
printf("NHYP_DEBUG turned on\n");
#endif
#ifdef CG_DEBUG
printf("CG_DEBUG turned on\n");
#endif
#ifdef CGTIME
printf("CGTIME turned on\n");
#endif
time_stamp("start");
status = get_prompt(stdin, &prompt);
IF_OK status += get_i(stdin, prompt, "nx", &par_buf.nx);
IF_OK status += get_i(stdin, prompt, "ny", &par_buf.ny);
IF_OK status += get_i(stdin, prompt, "nz", &par_buf.nz);
IF_OK status += get_i(stdin, prompt, "nt", &par_buf.nt);
IF_OK status += get_i(stdin, prompt, "iseed", &par_buf.iseed);
if (status > 0)
par_buf.stopflag = 1;
else
par_buf.stopflag = 0;
}
// Broadcast parameter buffer from node 0 to all other nodes
broadcast_bytes((char *)&par_buf, sizeof(par_buf));
if (par_buf.stopflag != 0)
normal_exit(0);
nx = par_buf.nx;
ny = par_buf.ny;
nz = par_buf.nz;
nt = par_buf.nt;
iseed = par_buf.iseed;
this_node = mynode();
number_of_nodes = numnodes();
volume = nx * ny * nz * nt;
total_iters = 0;
return prompt;
}
// -----------------------------------------------------------------
// -----------------------------------------------------------------
// Allocate all space for fields
void make_fields() {
int ipbp;
Real size = (Real)(8.0 * sizeof(matrix));
FIELD_ALLOC_VEC(gauge_field, matrix, 4);
FIELD_ALLOC_VEC(gauge_field_thin, matrix, 4);
size += (Real)((4.0 + 4.0 * 12.0) * sizeof(matrix));
FIELD_ALLOC_MAT_OFFDIAG(hyplink1, matrix, 4);
FIELD_ALLOC_MAT_OFFDIAG(hyplink2, matrix, 4);
FIELD_ALLOC_MAT_OFFDIAG(Staple1, matrix, 4);
FIELD_ALLOC_MAT_OFFDIAG(Staple2, matrix, 4);
FIELD_ALLOC_VEC(Staple3, matrix, 4);
size += (Real)(sizeof(matrix));
FIELD_ALLOC(tempmat, matrix);
size *= sites_on_node;
node0_printf("Mallocing %.1f MBytes per core for fields\n", size / 1e6);
}
// -----------------------------------------------------------------
// -----------------------------------------------------------------
int setup() {
int prompt;
// Print banner, get volume, seed
prompt = initial_set();
// Initialize the node source number generator
initialize_prn(&node_prn, iseed, volume + mynode());
// Initialize the layout functions, which decide where sites live
setup_layout();
// Allocate space for lattice, set up coordinate fields
make_lattice();
// Set up neighbor pointers and comlink structures
make_nn_gathers();
// Allocate space for fields
make_fields();
// Set up staggered phase vectors, boundary conditions
phaseset();
return(prompt);
}
// -----------------------------------------------------------------
// -----------------------------------------------------------------
// Read in parameters for SU(3) Monte Carlo
int readin(int prompt) {
// prompt=1 indicates prompts are to be given for input
int status, ipbp;
Real x;
// On node zero, read parameters and send to all other nodes
if (this_node == 0) {
printf("\n\n");
status = 0;
// Smearing parameters
IF_OK status += get_i(stdin, prompt, "Nsmear", &par_buf.Nsmear);
IF_OK status += get_f(stdin, prompt, "alpha_hyp0", &par_buf.alpha_hyp0);
IF_OK status += get_f(stdin, prompt, "alpha_hyp1", &par_buf.alpha_hyp1);
IF_OK status += get_f(stdin, prompt, "alpha_hyp2", &par_buf.alpha_hyp2);
// Number of stochastic sources
IF_OK status += get_i(stdin, prompt, "npbp", &par_buf.npbp);
// Which order polynomial to use
IF_OK status += get_i(stdin, prompt, "order", &par_buf.order);
// Number of Omegas and the interval
IF_OK status += get_i(stdin, prompt, "npts", &par_buf.npts);
IF_OK status += get_f(stdin, prompt, "startomega", &par_buf.startomega);
IF_OK status += get_f(stdin, prompt, "spacing", &par_buf.spacing);
// Maximum conjugate gradient iterations and restarts
IF_OK status += get_i(stdin, prompt, "max_cg_iterations", &par_buf.niter);
IF_OK status += get_i(stdin, prompt, "max_cg_restarts", &par_buf.nrestart);
// Error per site for conjugate gradient
IF_OK {
status += get_f(stdin, prompt, "error_per_site", &x);
par_buf.rsqmin = x * x;
}
// Find out what kind of starting lattice to use
IF_OK status += ask_starting_lattice(stdin, prompt, &par_buf.startflag,
par_buf.startfile);
if (status > 0)
par_buf.stopflag = 1;
else
par_buf.stopflag = 0;
}
// Broadcast parameter buffer from node0 to all other nodes
broadcast_bytes((char *)&par_buf, sizeof(par_buf));
if (par_buf.stopflag != 0)
normal_exit(0);
Nsmear = par_buf.Nsmear;
alpha_smear[0] = par_buf.alpha_hyp0;
alpha_smear[1] = par_buf.alpha_hyp1;
alpha_smear[2] = par_buf.alpha_hyp2;
// Include some mallocs here (which is called after make_fields)
npbp = par_buf.npbp;
source = malloc(npbp * sizeof(vector *)); // Stochastic sources
for (ipbp = 0; ipbp < npbp; ipbp++)
FIELD_ALLOC(source[ipbp], vector);
Norder = par_buf.order;
coeffs = malloc((Norder + 1) * sizeof(double)); // Polynomial coefficients
Npts = par_buf.npts;
spacing = par_buf.spacing;
M = 0.5 * par_buf.startomega; // !!! Note factor of 2
niter = par_buf.niter;
nrestart = par_buf.nrestart;
rsqmin = par_buf.rsqmin;
startflag = par_buf.startflag;
strcpy(startfile, par_buf.startfile);
// Do whatever is needed to get lattice
if (startflag == CONTINUE)
rephase(OFF);
startlat_p = reload_lattice(startflag, startfile);
// If a lattice was read in, put in staggered phase factors
// and antiperiodic boundary condition
phases_in = OFF;
rephase(ON);
return 0;
}
// -----------------------------------------------------------------