-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlg_app_slave.cpp
221 lines (211 loc) · 7.27 KB
/
dlg_app_slave.cpp
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
220
221
//
// Created by wsl on 2017-7-30.
//
#include "data.h"
#include "cmd_slave.h"
#include <fstream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include "sagecal.h"
using namespace std;
using namespace Data;
typedef struct _app_data {
char func[40];
char cmdfile[200];
} app_data;
static inline app_data *to_app_data(dlg_app_info *app) {
return (app_data *)app->data;
}
static inline unsigned long usecs(struct timeval *start, struct timeval *end) {
return (end->tv_sec - start->tv_sec) * 1000000 + (end->tv_usec - start->tv_usec);
}
static inline void ParseCmdLine(char *cmd_file) {
ifstream infile(cmd_file);
if (!infile.good()) {
cout << "File " << cmd_file << " does not exist." << endl;
exit(1);
}
int argc=0;
char **args = new char *[108];
string buffer;
if (infile.is_open()) {
while (infile.good()) {
std::getline(infile, buffer);
if (buffer.length() > 0) {
char *cmdline = new char[buffer.size() + 1];
strcpy(cmdline, buffer.c_str());
cmdline[buffer.size()] = '\0';
char * pch = strtok (cmdline, " ");
args[argc++] = pch;
while ( pch!= NULL) {
pch = strtok (NULL, " ");
args[argc++] = pch;
}
}
}
for(int i=0;i<argc-2;i=i+2) {
if( args[i][0]!= '-') {
i = i - 1;
continue;
}
char c = args[i][1];
switch (c) {
case 's':
Data::SkyModel = args[i+1];
break;
case 'c':
Data::Clusters = args[i+1];
break;
case 'p':
Data::solfile = args[i+1];
break;
case 'g':
Data::max_iter = atoi(args[i+1]);
break;
case 'a':
Data::DoSim = atoi(args[i+1]);
if (Data::DoSim < 0) { Data::DoSim = 1; }
break;
case 'b':
Data::doChan = atoi(args[i+1]);
if (Data::doChan > 1) { Data::doChan = 1; }
break;
case 'B':
Data::doBeam = atoi(args[i+1]);
if (Data::doBeam > 1) { Data::doBeam = 1; }
break;
case 'S':
Data::shareDir = args[i+1];
break;
case 'F':
Data::format = atoi(args[i+1]);
if (Data::format > 1) { Data::format = 1; }
break;
case 'e':
Data::max_emiter = atoi(args[i+1]);
break;
case 'l':
Data::max_lbfgs = atoi(args[i+1]);
break;
case 'm':
Data::lbfgs_m = atoi(args[i+1]);
break;
case 'j':
Data::solver_mode = atoi(args[i+1]);
break;
case 't':
Data::TileSize = atoi(args[i+1]);
break;
case 'I':
Data::DataField = args[i+1];
break;
case 'O':
Data::OutField = args[i+1];
break;
case 'n':
Data::Nt = atoi(args[i+1]);
break;
case 'k':
Data::ccid = atoi(args[i+1]);
break;
case 'o':
Data::rho = atof(args[i+1]);
break;
case 'L':
Data::nulow = atof(args[i+1]);
break;
case 'H':
Data::nuhigh = atof(args[i+1]);
break;
case 'R':
Data::randomize = atoi(args[i+1]);
break;
case 'W':
Data::whiten = atoi(args[i+1]);
break;
case 'J':
Data::phaseOnly = atoi(args[i+1]);
break;
case 'x':
Data::min_uvcut = atof(args[i+1]);
break;
case 'y':
Data::max_uvcut = atof(args[i+1]);
break;
case 'z':
Data::ignorefile = args[i+1];
break;
case 'v':
Data::verbose = 1;
break;
case 'D':
Data::DoDiag = atoi(args[i+1]);
if (Data::DoDiag < 0) { Data::DoDiag = 0; }
break;
}
}
}
}
int init(dlg_app_info *app, const char ***params)
{
const char **param;
while (1) {
param = *params;
// Sentinel
if (param == NULL) {
break;
}
if (strcmp(param[0], "func") == 0) {
Data::func = (char *)param[1];
} else if(strcmp(param[0], "cmdfile") == 0) {
Data::cmdFile = (char *)param[1];
}
params++;
}
if(Data::func==NULL||Data::cmdFile==NULL) {
printf("func or cmdfile not configured\n");
return 1;
}
app->data = malloc(sizeof(app_data));
strcpy(to_app_data(app)->func,Data::func);
strcpy(to_app_data(app)->cmdfile,Data::cmdFile);
return 0;
}
int run(dlg_app_info *app) {
struct timeval start, end;
gettimeofday(&start, NULL);
printf("------------------slave begin run %s, [%s]------------------\n", app->uid, to_app_data(app)->func);
ParseCmdLine(to_app_data(app)->cmdfile);
double duration = 0.;
if(strcmp(to_app_data(app)->func, "aux_reader") == 0) {
aux_reader(app);
} else if(strcmp(to_app_data(app)->func, "fratio_slave") == 0) {
fratio_slave(app);
} else if(strcmp(to_app_data(app)->func, "admm_slave") == 0) {
admm_slave(app);
} else if(strcmp(to_app_data(app)->func, "coh_slave") == 0) {
coh_slave(app);
} else if(strcmp(to_app_data(app)->func, "sagefit_slave") == 0) {
sagefit_slave(app);
} else if(strcmp(to_app_data(app)->func, "update_y_slave") == 0) {
update_y_slave(app);
} else if(strcmp(to_app_data(app)->func, "write_residual_slave") == 0) {
write_residual_slave(app);
} else {
printf("------------------slave wrong func parameter:%s------------------\n", to_app_data(app)->func);
free(app->data);
return 1;
}
gettimeofday(&end, NULL);
duration = usecs(&start, &end) / 1000000.;
printf("------------------slave end run %s, [%s] used %.3f's------------------\n", app->uid, to_app_data(app)->func, duration);
return 0;
}
void drop_completed(dlg_app_info *app, const char *uid, drop_status status) {
printf("slave trigger....drop_completed\n");
app->done(APP_FINISHED);
free(app->data);
}