-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp.cpp
362 lines (320 loc) · 13.5 KB
/
exp.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
//for intf_to_ip
// #include <cstring>
// #include <sys/types.h>
// #include <sys/socket.h>
// #include <sys/ioctl.h>
// #include <netinet/in.h>
// #include <net/if.h>
// #include <unistd.h>
// #include <arpa/inet.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ifaddrs.h>
//
#include <getopt.h>
#include "profiler.h"
#include "dataspaces_wa.h"
int get_data_length(int ndim, uint64_t* gdim_, uint64_t* lb_, uint64_t* ub_)
{
uint64_t dim_length[ndim];
for(int i = 0; i < ndim; i++) {
uint64_t lb = lb_[i];
if (lb < 0 || lb > gdim_[i] ) {
log_(ERROR, "lb= " << lb << " is not feasible!")
return 0;
}
uint64_t ub = ub_[i];
if (ub < 0 || ub > gdim_[i] || ub < lb) {
log_(ERROR, "ub= " << ub << " is not feasible!")
return 0;
}
dim_length[i] = ub - lb;
}
int volume = 1;
for(int i = 0; i < ndim; i++)
volume *= (int)dim_length[i];
return volume;
}
std::string intf_to_ip(std::string intf)
{
struct ifaddrs *ifaddr, *ifa;
int family, s;
char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL)
continue;
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if ((strcmp(ifa->ifa_name, intf.c_str() ) == 0) && (ifa->ifa_addr->sa_family == AF_INET) ) {
if (s) {
printf("getnameinfo() failed: %s\n", gai_strerror(s) );
exit(EXIT_FAILURE);
}
// printf("\t Interface : <%s>\n",ifa->ifa_name);
// printf("\t Address : <%s>\n", host);
break;
}
}
freeifaddrs(ifaddr);
return boost::lexical_cast<std::string>(host);
}
// std::string intf_to_ip(std::string intf)
// {
// int fd;
// struct ifreq ifr;
// //
// fd = socket(AF_INET, SOCK_DGRAM, 0);
// // Type of address to retrieve - IPv4 IP address
// ifr.ifr_addr.sa_family = AF_INET;
// // Copy the interface name in the ifreq structure
// std::memcpy(ifr.ifr_name, intf.c_str(), IFNAMSIZ - 1);
// ioctl(fd, SIOCGIFADDR, &ifr);
// close(fd);
// //
// return boost::lexical_cast<std::string>(inet_ntoa( ( (struct sockaddr_in*)&ifr.ifr_addr)->sin_addr) );
// }
std::map<std::string, std::string> parse_opts(int argc, char** argv)
{
std::map<std::string, std::string> opt_map;
//
int c;
static struct option long_options[] =
{
{"type", optional_argument, NULL, 0},
{"cl_id", optional_argument, NULL, 1},
{"base_client_id", optional_argument, NULL, 2},
{"num_peer", optional_argument, NULL, 3},
{"ds_id", optional_argument, NULL, 4},
{"lcontrol_lintf", optional_argument, NULL, 5},
{"lcontrol_lport", optional_argument, NULL, 6},
{"join_lcontrol_lip", optional_argument, NULL, 7},
{"join_lcontrol_lport", optional_argument, NULL, 8},
{"control_lintf", optional_argument, NULL, 9},
{"control_lport", optional_argument, NULL, 10},
{"join_control_lip", optional_argument, NULL, 11},
{"join_control_lport", optional_argument, NULL, 12},
{"trans_protocol", optional_argument, NULL, 13},
{"ib_lintf", optional_argument, NULL, 14},
{"tcp_lintf", optional_argument, NULL, 15},
{"tcp_lport", optional_argument, NULL, 16},
{"gftp_lintf", optional_argument, NULL, 17},
{"gftp_lport", optional_argument, NULL, 18},
{"tmpfs_dir", optional_argument, NULL, 19},
{"w_prefetch", optional_argument, NULL, 20},
{0, 0, 0, 0}
};
while (1) {
int option_index = 0;
c = getopt_long (argc, argv, "", long_options, &option_index);
if (c == -1) // Detect the end of the options.
break;
switch (c) {
case 0:
opt_map["type"] = optarg;
break;
case 1:
opt_map["cl_id"] = optarg;
break;
case 2:
opt_map["base_client_id"] = optarg;
break;
case 3:
opt_map["num_peer"] = optarg;
break;
case 4:
opt_map["ds_id"] = optarg;
break;
case 5:
opt_map["lcontrol_lintf"] = optarg;
break;
case 6:
opt_map["lcontrol_lport"] = optarg;
break;
case 7:
opt_map["join_lcontrol_lip"] = optarg;
break;
case 8:
opt_map["join_lcontrol_lport"] = optarg;
break;
case 9:
opt_map["control_lintf"] = optarg;
break;
case 10:
opt_map["control_lport"] = optarg;
break;
case 11:
opt_map["join_control_lip"] = optarg;
break;
case 12:
opt_map["join_control_lport"] = optarg;
break;
case 13:
opt_map["trans_protocol"] = optarg;
break;
case 14:
opt_map["ib_lintf"] = optarg;
break;
case 15:
opt_map["tcp_lintf"] = optarg;
break;
case 16:
opt_map["tcp_lport"] = optarg;
break;
case 17:
opt_map["gftp_lintf"] = optarg;
break;
case 18:
opt_map["gftp_lport"] = optarg;
break;
case 19:
opt_map["tmpfs_dir"] = optarg;
break;
case 20:
opt_map["w_prefetch"] = optarg;
break;
case '?':
break; //getopt_long already printed an error message.
default:
break;
}
}
if (optind < argc) {
std::cout << "non-option ARGV-elements: \n";
while (optind < argc)
std::cout << "\t" << argv[optind++] << "\n";
}
//
log_(INFO, "opt_map= \n" << patch::map_to_str<>(opt_map) )
return opt_map;
}
#define TEST_SIZE 256
#define TEST_NDIM 3
#define TEST_DATASIZE pow(TEST_SIZE, TEST_NDIM)
#define TEST_VER 0
#define TEST_SGDIM TEST_DATASIZE
int test(std::string type, std::string var_name, WADSDriver& wads_driver)
{
int err;
uint64_t* gdim_ = (uint64_t*)malloc(TEST_NDIM*sizeof(uint64_t) );
uint64_t* lb_ = (uint64_t*)malloc(TEST_NDIM*sizeof(uint64_t) );
uint64_t* ub_ = (uint64_t*)malloc(TEST_NDIM*sizeof(uint64_t) );
for (int i = 0; i < TEST_NDIM; i++) {
lb_[i] = 0;
ub_[i] = TEST_SIZE - 1;
gdim_[i] = TEST_SIZE - 1;
}
int* data_ = (int*)malloc(TEST_DATASIZE*sizeof(int) );
if (str_cstr_equals(type, "put") ) {
// for (int i = 0; i < TEST_DATASIZE; i++)
// data_[i] = i + 1;
return_if_err(wads_driver.put(var_name, TEST_VER, "int", sizeof(int), TEST_NDIM, gdim_, lb_, ub_, data_), err, patch::free_all<uint64_t>(3, gdim_, lb_, ub_);)
log_(INFO, "put; kv= " << KV_TO_STR(var_name, TEST_VER) << "\n"
<< "\t data_size= "<< (float)sizeof(int)*get_data_length(TEST_NDIM, gdim_, lb_, ub_) / (1024*1024) << " MB")
}
else if (str_cstr_equals(type, "get") ) {
return_if_err(wads_driver.get(true, var_name, TEST_VER, "int", sizeof(int), TEST_NDIM, gdim_, lb_, ub_, data_), err, patch::free_all<uint64_t>(3, gdim_, lb_, ub_);)
log_(INFO, "got; kv= " << KV_TO_STR(var_name, TEST_VER) << "\n"
<< "\t data_size= " << (float)sizeof(int)*get_data_length(TEST_NDIM, gdim_, lb_, ub_) / (1024*1024) << " MB")
}
else {
log_(ERROR, "unknown type= " << type)
return 1;
}
patch::free_all<uint64_t>(3, gdim_, lb_, ub_);
free(data_);
}
int main(int argc , char **argv)
{
std::string temp;
google::InitGoogleLogging(argv[0] );
//
std::map<std::string, std::string> opt_map = parse_opts(argc, argv);
TProfiler<std::string> tprofiler;
if (str_cstr_equals(opt_map["type"], "put") || str_cstr_equals(opt_map["type"], "get") ) {
MWADSDriver wads_driver(
boost::lexical_cast<int>(opt_map["cl_id"] ), boost::lexical_cast<int>(opt_map["base_client_id"] ), boost::lexical_cast<int>(opt_map["num_peer"] ),
intf_to_ip(opt_map["lcontrol_lintf"] ), boost::lexical_cast<int>(opt_map["lcontrol_lport"] ), opt_map["join_lcontrol_lip"], boost::lexical_cast<int>(opt_map["join_lcontrol_lport"] ) );
std::cout << "Enter for " << opt_map["type"] << " test... \n";
getline(std::cin, temp);
tprofiler.add_event("test", "test");
test(opt_map["type"], "dummy", wads_driver);
tprofiler.end_event("test");
std::cout << "Enter \n";
getline(std::cin, temp);
}
else if (str_cstr_equals(opt_map["type"], "ri") ) {
std::list<std::string> ib_lport_list;
for (int port = 1234; port < 1299; port++)
ib_lport_list.push_back(boost::lexical_cast<std::string>(port) );
PALGO_T palgo_t = MALGO_W_PPM;
int max_num_key_ver_in_mpbuffer = 10;
// SALGO_T salgo_t = SALGO_H;
// COOR_T lcoor_[] = { BOOST_PP_ENUM(NDIM, FIXED_REP, 0) };
// COOR_T ucoor_[] = { BOOST_PP_ENUM(NDIM, FIXED_REP, 16) };
// int sexpand_length = 1;
if (opt_map.count("join_lcontrol_lip") == 0) {
opt_map["join_lcontrol_lip"] = "";
opt_map["join_lcontrol_lport"] = "0";
}
// std::string lcontrol_lip = intf_to_ip(opt_map["lcontrol_lintf"] );
// std::string control_lip = intf_to_ip(opt_map["control_lintf"] );
// std::string ib_lip = intf_to_ip(opt_map["ib_lintf"] );
// std::string tcp_lip = intf_to_ip(opt_map["tcp_lintf"] );
// std::string gftp_lip = intf_to_ip(opt_map["gftp_lintf"] );
// log_(INFO, "lcontrol_lip= " << lcontrol_lip << "\n"
// << "control_lip= " << control_lip << "\n"
// << "ib_lip= " << ib_lip << "\n"
// << "tcp_lip= " << tcp_lip << "\n"
// << "gftp_lip= " << gftp_lip << "\n")
if (str_cstr_equals(opt_map["join_control_lip"], "") ) {
MMRIManager ri_manager(
boost::lexical_cast<int>(opt_map["cl_id"] ), boost::lexical_cast<int>(opt_map["base_client_id"] ), boost::lexical_cast<int>(opt_map["num_peer"] ),
intf_to_ip(opt_map["lcontrol_lintf"] ), boost::lexical_cast<int>(opt_map["lcontrol_lport"] ), opt_map["join_lcontrol_lip"], boost::lexical_cast<int>(opt_map["join_lcontrol_lport"] ),
boost::lexical_cast<int>(opt_map["ds_id"] ), intf_to_ip(opt_map["control_lintf"] ), boost::lexical_cast<int>(opt_map["control_lport"] ), opt_map["join_control_lip"], boost::lexical_cast<int>(opt_map["join_control_lport"] ),
palgo_t, max_num_key_ver_in_mpbuffer, boost::lexical_cast<bool>(opt_map["w_prefetch"] ),
opt_map["trans_protocol"], intf_to_ip(opt_map["ib_lintf"] ), ib_lport_list,
intf_to_ip(opt_map["tcp_lintf"] ), boost::lexical_cast<int>(opt_map["tcp_lport"] ),
opt_map["gftp_lintf"], intf_to_ip(opt_map["gftp_lintf"] ), opt_map["gftp_lport"], opt_map["tmpfs_dir"] );
// SMRIManager ri_manager(
// boost::lexical_cast<int>(opt_map["cl_id"] ), boost::lexical_cast<int>(opt_map["base_client_id"] ), boost::lexical_cast<int>(opt_map["num_peer"] ),
// intf_to_ip(opt_map["lcontrol_lintf"] ), boost::lexical_cast<int>(opt_map["lcontrol_lport"] ), opt_map["join_lcontrol_lip"], boost::lexical_cast<int>(opt_map["join_lcontrol_lport"] ),
// boost::lexical_cast<int>(opt_map["ds_id"] ), intf_to_ip(opt_map["control_lintf"] ), boost::lexical_cast<int>(opt_map["control_lport"] ), opt_map["join_control_lip"], boost::lexical_cast<int>(opt_map["join_control_lport"] ),
// salgo_t, lcoor_, ucoor_, sexpand_length, boost::lexical_cast<bool>(opt_map["w_prefetch"] ),
// opt_map["trans_protocol"], intf_to_ip(opt_map["ib_lintf"] ), ib_lport_list,
// intf_to_ip(opt_map["tcp_lintf"] ), boost::lexical_cast<int>(opt_map["tcp_lport"] ),
// opt_map["gftp_lintf"], intf_to_ip(opt_map["gftp_lintf"] ), opt_map["gftp_lport"], opt_map["tmpfs_dir"] );
std::cout << "Enter \n";
getline(std::cin, temp);
}
else {
MSRIManager ri_manager(
boost::lexical_cast<int>(opt_map["cl_id"] ), boost::lexical_cast<int>(opt_map["base_client_id"] ), boost::lexical_cast<int>(opt_map["num_peer"] ),
intf_to_ip(opt_map["lcontrol_lintf"] ), boost::lexical_cast<int>(opt_map["lcontrol_lport"] ), opt_map["join_lcontrol_lip"], boost::lexical_cast<int>(opt_map["join_lcontrol_lport"] ),
boost::lexical_cast<int>(opt_map["ds_id"] ), intf_to_ip(opt_map["control_lintf"] ), boost::lexical_cast<int>(opt_map["control_lport"] ), opt_map["join_control_lip"], boost::lexical_cast<int>(opt_map["join_control_lport"] ),
opt_map["trans_protocol"], intf_to_ip(opt_map["ib_lintf"] ), ib_lport_list,
intf_to_ip(opt_map["tcp_lintf"] ), boost::lexical_cast<int>(opt_map["tcp_lport"] ),
opt_map["gftp_lintf"], intf_to_ip(opt_map["gftp_lintf"] ), opt_map["gftp_lport"], opt_map["tmpfs_dir"] );
// SSRIManager ri_manager(
// boost::lexical_cast<int>(opt_map["cl_id"] ), boost::lexical_cast<int>(opt_map["base_client_id"] ), boost::lexical_cast<int>(opt_map["num_peer"] ),
// intf_to_ip(opt_map["lcontrol_lintf"] ), boost::lexical_cast<int>(opt_map["lcontrol_lport"] ), opt_map["join_lcontrol_lip"], boost::lexical_cast<int>(opt_map["join_lcontrol_lport"] ),
// boost::lexical_cast<int>(opt_map["ds_id"] ), intf_to_ip(opt_map["control_lintf"] ), boost::lexical_cast<int>(opt_map["control_lport"] ), opt_map["join_control_lip"], boost::lexical_cast<int>(opt_map["join_control_lport"] ),
// opt_map["trans_protocol"], intf_to_ip(opt_map["ib_lintf"] ), ib_lport_list,
// intf_to_ip(opt_map["tcp_lintf"] ), boost::lexical_cast<int>(opt_map["tcp_lport"] ),
// opt_map["gftp_lintf"], intf_to_ip(opt_map["gftp_lintf"] ), opt_map["gftp_lport"], opt_map["tmpfs_dir"] );
std::cout << "Enter \n";
getline(std::cin, temp);
}
// patch::syncer<char> dummy_syncer;
// dummy_syncer.add_sync_point('d', 1);
// dummy_syncer.wait('d');
}
else {
log_(ERROR, "unknown type= " << opt_map["type"] )
}
log_(INFO, "tprofiler= \n" << tprofiler.to_str() )
return 0;
}